pCount
to store the frequency of each character in p
.sCount
to store the frequency of each character in the current window of s
.result
to store the starting indices of anagrams of p
in s
.pCount
with the frequency of each character in p
.sCount
with the frequency of each character in the first window of s
.s
with a window of size equal to the length of p
:
a. If the current window's sCount
matches pCount
, add the start index of the window to result
.
b. Move the window one character to the right: decrement the count of the character going out of the window and increment the count of the character coming into the window in sCount
.result
list.