Find All Anagrams in a String

Medium

Given s and p, return the start indices of every substring of s that is an anagram of p.

The result must be in ascending order.

Example 1

findAnagrams()
Input
s = "cbaebabacd", p = "abc"
Output
[0,6]

Example 2

findAnagrams()
Input
s = "abab", p = "ab"
Output
[0,1,2]
Constraints
1 <= s.length, p.length <= 3 * 10^4
Both strings are lowercase English letters.

Topics

StringsSliding WindowHash Table

Implement findAnagrams in the editor and return the answer — printing it is never graded.