Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.
Java
Find All Anagrams
Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.
Example 1:
Input: {"s":"cbaebabacd","p":"abc"}
Output: [0,6]
Input
arr ={"s":"cbaebabacd","p":"abc"}
s = "cbaebabacd"
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
Window:
[0...2]
Matches:
0
Pattern "abc" character count
Empty
Current window character count
Empty
Algorithm Insight:
Slide a window of size |p| over s. If the window's character count matches p's count, it's an anagram. Track all starting indices where anagrams are found.