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
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
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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
- Initialize: Create a frequency count for the string
pusing a dictionary (or array) to store the count of each character. - Setup Sliding Window: Create a sliding window of the same leng...
Submit Your Answer
Markdown supported