You’re given two strings, 'text' of length 'n' and 'pattern' of length 'm', consisting of lowercase characters.
Find all the occurrences of the string ‘pattern’ in ‘text’.
For each occurrence, print the index from where it starts in the string ‘text’ (1 - indexed).
Input: ‘text’ = “cxyzghxyzvjkxyz” and ‘pattern’ = “xyz”
Output: 2 7 13
Explanation: The pattern ‘pattern’ = “xyz” appears at 3 positions in ‘text’.
cxyzghxyzvjkxyz
xyz
3
2 7 13
The pattern ‘pattern’ = “xyz” appears at 3 positions in ‘text’.
ababacabab
aba
3
1 3 7
Here we have an overlap between the first occurrence (at position 1) and the second occurrence (at position 3), and we are considering both.
abcd
xy
0
The expected time complexity is O(‘n’ + ‘m’).
1 <= ‘n’ <= 10^5
1 <= ‘m’ <= ‘n’