Use the KMP algorithm to preprocess the pattern into a longest proper prefix-suffix (LPS) array, then scan the text in O(n+m) time. After each match, continue scanning from the next character (not skipping the pattern length) to capture overlapping occurrences. Yield True for each match found.
Pro tip: Emphasize that the LPS array allows the scan to resume without re-examining characters, and explicitly state that overlapping matches are handled by not advancing past the matched suffix. This shows you understand the algorithm's mechanics and can adapt it to the requirement.
Confirm that the pattern can be empty, the string length, and whether case sensitivity matters. Discuss expected time/space complexity and the need to handle overlapping matches.
Select KMP for O(n+m) time, explaining why naive O(n*m) is unacceptable. Mention that KMP naturally supports overlapping matches by design.
Preprocess the pattern to compute the longest proper prefix that is also a suffix for each position. This enables efficient fallback during mismatches.
Iterate through the string, using the LPS array to skip redundant comparisons. When a full match is found, yield True and set the pattern index to lps[pattern_index-1] to allow overlapping matches.
Test with overlapping patterns (e.g., 'aa' in 'aaaa'), edge cases (empty pattern, no match), and analyze time/space complexity. Discuss trade-offs with other algorithms like Rabin-Karp.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.