Pattern occurrences

Write codeMedium25 min

Your task

Given a text string t and a non-empty pattern p, return a list (ascending) of all starting indices where p occurs in t. Occurrences may overlap. 1 <= len(p) <= len(t) <= 100000, lowercase letters. Example: p='aa', t='aaaa' -> [0,1,2].

Examples

find_all_occurrences(t: str, p: str) -> list[int]
Example 1
Inputfind_all_occurrences("aaaa", "aa")
Output[0, 1, 2]