Basic example
Input
s = "cbaebabacd", p = "abc"
Output
[0, 6]
The substring at index 0 is "cba" which is an anagram of "abc". The substring at index 6 is "bac" which is also an anagram.
Full lesson preview
Return all starting indices of p's anagrams in s using sliding window and frequency counting.
Problem statement
Task
Examples
Input
s = "cbaebabacd", p = "abc"
Output
[0, 6]
The substring at index 0 is "cba" which is an anagram of "abc". The substring at index 6 is "bac" which is also an anagram.
Input format
Output format
Constraints
Samples
Input
s = "abab", p = "ab"
Output
[0, 1, 2]
All substrings "ab","ba","ab" are anagrams of "ab" at indices 0,1,2.