EvalFrame Technical Mock Interviews & Coding Practice

Find All Anagrams in a String

Medium · String / Sliding Window · Algorithm problem · all problems

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. **Examples:** ```typescript findAnagrams("cbaebabacd", "abc") // [0, 6] findAnagrams("abab", "ab") // [0, 1, 2] ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(n)
  • Space complexity: O(1)

Fixed-size sliding window shifts across string s in O(n) time.

Follow-Up Questions Interviewers Ask About Find All Anagrams in a String

  • How can you avoid the 26-element array comparison in each step?
    Maintain a match counter of how many character frequencies currently match between sCount and pCount.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.