This question evaluates understanding of string pattern matching and generator/iterator design, testing skills in handling overlapping matches, streaming output, and worst-case time complexity considerations.
Write a generator that scans a string and emits a value whenever a substring matches a given pattern.
s
pattern
(non-empty)
Return a generator/iterator that yields True once for each occurrence of pattern in s, scanning from left to right. Matches may overlap.
s = "aaaa"
,
pattern = "aa"
→ yields
True
3 times (matches at indices 0, 1, 2)
s = "abc"
,
pattern = "d"
→ yields nothing
0 <= len(s) <= 10^6
1 <= len(pattern) <= 10^5