#C13208. Anagram Substring Indices
Anagram Substring Indices
Anagram Substring Indices
You are given two strings: a target word and a text string s. Your task is to find all the starting indices of the substrings in s which are anagrams of the given word.
Formally, for a given word \(W\) of length \(n\) and a string \(S\) of length \(m\), find all indices \(i\) (0-indexed) such that the substring \(S[i, i+n-1]\) is an anagram of \(W\). An anagram of \(W\) is any permutation of the characters in \(W\>.
Example:
- For \(W = \texttt{ab}\) and \(S = \texttt{abxaba}\), the valid starting indices are 0, 3, and 4.
This problem involves using a sliding window technique to efficiently compare character counts between the word and substrings of the given string.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains the target word, \(W\).
- The second line contains the text string, \(S\).
Both \(W\) and \(S\) consist only of characters. It is guaranteed that \(W\) and \(S\) are non-null (though \(S\) can be an empty string).
outputFormat
The output should be written to standard output (stdout) as a single line containing the starting indices (0-indexed) of all anagram substrings of \(W\) in \(S\), separated by a single space. If no anagrams are found, output an empty line.
## sampleab
abxaba
0 3 4
</p>