Find All Anagrams in a String

Medium · Arrays & Strings · about 20 minutes

Asked at Amazon, Meta, Microsoft.

Given strings s and p, return the start indices (in increasing order) of every substring of s that is an anagram of p — the same letters with the same counts, in any order. Both strings contain only lowercase English letters.

Related guides