


from __future__ import annotations







def        _lowerCamelCase(	lowercase__   , lowercase__	)						->	bool:

		'''simple docstring'''







		__lowercase=			get_failure_array(lowercase__	)

		# 2) Step through text searching for pattern
		__lowercase,							__lowercase=			0, 0  # index into text, pattern
		while i < len(lowercase__	):
				if pattern[j] == text[i]:
						if j == (len(lowercase__	) - 1):
								return True
						j += 1

				# if this is a prefix in our pattern
				# just go back far enough to continue
				elif j > 0:
						__lowercase=			failure[j - 1]
						continue
				i += 1
		return False







def        _lowerCamelCase(	lowercase__	)						->	list[int]:

		'''simple docstring'''







		__lowercase=			[0]
		__lowercase=			0
		__lowercase=			1
		while j < len(lowercase__	):
				if pattern[i] == pattern[j]:
						i += 1
				elif i > 0:
						__lowercase=			failure[i - 1]
						continue
				j += 1
				failure.append(lowercase__	)
		return failure


if __name__ == "__main__":
	# Test 1)
	lowerCAmelCase           =		'''abc1abc12'''
	lowerCAmelCase           =		'''alskfjaldsabc1abc1abc12k23adsfabcabc'''
	lowerCAmelCase           =		'''alskfjaldsk23adsfabcabc'''
	assert kmp(pattern, texta) and not kmp(pattern, texta)

	# Test 2)
	lowerCAmelCase           =		'''ABABX'''
	lowerCAmelCase           =		'''ABABZABABYABABX'''
	assert kmp(pattern, text)

	# Test 3)
	lowerCAmelCase           =		'''AAAB'''
	lowerCAmelCase           =		'''ABAAAAAB'''
	assert kmp(pattern, text)

	# Test 4)
	lowerCAmelCase           =		'''abcdabcy'''
	lowerCAmelCase           =		'''abcxabcdabxabcdabcdabcy'''
	assert kmp(pattern, text)

	# Test 5)
	lowerCAmelCase           =		'''aabaabaaa'''
	assert get_failure_array(pattern) == [0, 1, 0, 1, 2, 3, 4, 5, 2]










from __future__ import annotations







def        _lowerCamelCase(	lowercase__   , lowercase__	)						->	bool:

		'''simple docstring'''







		__lowercase=			get_failure_array(lowercase__	)

		# 2) Step through text searching for pattern
		__lowercase,							__lowercase=			0, 0  # index into text, pattern
		while i < len(lowercase__	):
				if pattern[j] == text[i]:
						if j == (len(lowercase__	) - 1):
								return True
						j += 1

				# if this is a prefix in our pattern
				# just go back far enough to continue
				elif j > 0:
						__lowercase=			failure[j - 1]
						continue
				i += 1
		return False







def        _lowerCamelCase(	lowercase__	)						->	list[int]:

		'''simple docstring'''







		__lowercase=			[0]
		__lowercase=			0
		__lowercase=			1
		while j < len(lowercase__	):
				if pattern[i] == pattern[j]:
						i += 1
				elif i > 0:
						__lowercase=			failure[i - 1]
						continue
				j += 1
				failure.append(lowercase__	)
		return failure


if __name__ == "__main__":
	# Test 1)
	lowerCAmelCase           =		'''abc1abc12'''
	lowerCAmelCase           =		'''alskfjaldsabc1abc1abc12k23adsfabcabc'''
	lowerCAmelCase           =		'''alskfjaldsk23adsfabcabc'''
	assert kmp(pattern, texta) and not kmp(pattern, texta)

	# Test 2)
	lowerCAmelCase           =		'''ABABX'''
	lowerCAmelCase           =		'''ABABZABABYABABX'''
	assert kmp(pattern, text)

	# Test 3)
	lowerCAmelCase           =		'''AAAB'''
	lowerCAmelCase           =		'''ABAAAAAB'''
	assert kmp(pattern, text)

	# Test 4)
	lowerCAmelCase           =		'''abcdabcy'''
	lowerCAmelCase           =		'''abcxabcdabxabcdabcdabcy'''
	assert kmp(pattern, text)

	# Test 5)
	lowerCAmelCase           =		'''aabaabaaa'''
	assert get_failure_array(pattern) == [0, 1, 0, 1, 2, 3, 4, 5, 2]






