Find All Anagrams in a String

Last updated: June 17, 2026

Quick Overview

Given strings s and p, find all start indices of p's anagrams in s. Tests sliding window with character frequency counting, a common Google phone screen question.

Google
Coding & Algorithms
Software Engineer
Google
June 17, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

295

0

71 solved


Given strings s and p, find all start indices of p's anagrams in s. Tests sliding window with character frequency counting, a common Google phone screen question.

How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Problem Analysis

To solve the problem of finding all start indices of anagrams of string p in string s, we can utilize the sliding window technique combined with character frequency counting. This approach...

Approach
  1. Initialize: Create a frequency count for the string p using a dictionary (or array) to store the count of each character.
  2. Setup Sliding Window: Create a sliding window of the same leng...

Submit Your Answer
Markdown supported

Related Questions