Write find_all(text, pattern) -> list[int]: every start index i with text[i:i + len(pattern)] == pattern, in increasing order. Occurrences may overlap. Return [] if the pattern is empty or longer than the text.
find_all("abracadabra", "abra") # [0, 7]
find_all("aaaa", "aa") # [0, 1, 2] overlapping matches all count
find_all("ab", "abc") # []
Constraints: 0 <= len(pattern), len(text) <= 300_000, any characters.
⭐ Bonus: comparing the pattern at every position is O(n·m) and still passes; speed tests with a 300k-character text, a 150k-character pattern and 150,001 overlapping matches earn a star at O(n + m) (even confirming each match character by character is too slow there).
Show hint
Give the pattern and each same-length window of the text a numeric fingerprint (a polynomial hash), updating the window's value in O(1) as it slides one character. With a modulus as large as 2**61 - 1 and a large base, equal fingerprints can be trusted.