# Leetcode 438 - Find all anagrams in a string

Note:

• Use array instead of hash table to store counts. Because then we can quickly check if all number are 0 or undefined.
• When array[charIndex] !== undefined, move right by 1, and minus 1 from array[charIndex].
• If the array[charIndex] === 0, check if all elements are either 0 or undefined. If yes, we’ve found a res. Then move left by 1.
• If array[charIndex] < 0, move left and keep adding 1 to array[leftIndex] till array[charIndex] === 0.
• If array[charIndex] === undefined, right++, left = right. And RESET the array we used to count.

Question:

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.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Example:

Code: