#C1901. Find Pattern Indices

    ID: 45158 Type: Default 1000ms 256MiB

Find Pattern Indices

Find Pattern Indices

You are given two strings, pattern and text. Your task is to find all starting indices in text where the pattern occurs.

A match is defined as an occurrence of the pattern in text such that the substring of text beginning at that index is exactly equal to pattern. The indices are 0-indexed.

You can mathematically express the requirement as finding all indices \( i \) such that:

\[ \text{text}[i : i+\text{len}(pattern)] = \text{pattern} \]

Print the indices in increasing order separated by a single space. If no occurrence is found, print an empty line.

inputFormat

The input consists of two lines:

  • The first line contains the string pattern.
  • The second line contains the string text in which you are to search for pattern.

outputFormat

Output a single line containing all starting indices (0-indexed) where the pattern is found in the text, separated by a space. If the pattern does not occur in the text, output an empty line.

## sample
abc
abcabcabc
0 3 6