438. Find All Anagrams in a String

Practice Find All Anagrams in a String for free on NudgeCode: Medium, Sliding Window pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return every start index i such that the piece of s starting at i with length p.length uses exactly the same letters as p (same letters, same counts, any order). The indices can be returned in any order.

Example

s = "cbaebabacd", p = "abc"  ->  [0,6]   ("cba" and "bac")
s = "abab", p = "ab"         ->  [0,1,2]

Constraints