#C5469. Find All Anagrams in a String
Find All Anagrams in a String
Find All Anagrams in a String
Given two strings s and p, your task is to find all start indices of p's anagrams in s. An anagram is formed by rearranging all letters of a string. Formally, you need to find all indices i such that:
\( \text{Counter}(s[i:i+|p|]) = \text{Counter}(p) \)
This problem can be efficiently solved using a sliding window approach, where you maintain the frequency counts of the characters in the current window and compare them to the frequency count of p.
inputFormat
The input consists of two lines. The first line contains the string s. The second line contains the string p.
outputFormat
Output the starting indices of p's anagrams in s in increasing order, separated by a space. If no anagram is found, print an empty line.
## samplecbaebabacd
abc
0 6