#C13285. Find Substring Indices
Find Substring Indices
Find Substring Indices
You are given two strings: text
and pattern
. Your task is to find all starting indices where the pattern
occurs in the text
, allowing for overlapping occurrences.
More formally, for given strings \( T \) and \( P \) with lengths \( n \) and \( m \) respectively, find all indices \( i \) (0-indexed) such that:
[ T[i:i+m]=P ]
If no occurrence is found, output an empty result.
inputFormat
The input consists of two lines:
- The first line contains the string
text
. - The second line contains the string
pattern
.
outputFormat
Output a single line with the starting indices (0-indexed) where pattern
occurs in text
, separated by a single space. If no valid occurrence exists, output an empty line.
abracadabra
abra
0 7