Skip to content

visual walkthrough

Find All Anagrams in a String

MediumFixed-size Window + Frequency MapReported at: AmazonMicrosoftMeta+6

Same as Permutation in String but collecting every match.

Solve on LeetCode

The idea

Same fixed-size window as "permutation in string", but collect every start that matches instead of stopping at the first.

Counting letters and updating the counts as the window slides makes each step O(1).

Complexity

approachtimespace
Sort every windowO(n · m log m)O(m)
Slide with countsO(n)O(1)

More walkthroughs