Group Anagrams
Group strings that are anagrams of each other Return the groups in any order Example: ["eat","tea","tan","ate","nat","bat"] => [["bat"],["nat","tan"],["ate","eat","tea"]]
Group Anagrams is a classic scan-and-record problem: the right bookkeeping beats brute force. Interviewers love it because it reveals your data-structure instincts and your edge-case discipline. Watch your edge cases around repeats, and be clear about what your map is storing.
Examples
You write
group_anagrams(strs: List[str])
Example 1
- Input
- ["eat","tea","tan","ate","nat","bat"]
- returns
- [["bat"],["nat","tan"],["ate","eat","tea"]]
Example 2
- Input
- [""]
- returns
- [[""]]
The pattern behind it
Arrays & Hashing
I reach for it when
- You catch yourself scanning the array again for every element.
- The problem asks about duplicates, pairs, counts or groups.
Say this before you type. Say what the key is and what the value remembers, before you write the loop.
All 127 Arrays & Hashing problemsStrings
I reach for it when
- The input is text and the answer is a count, a substring or a new string.
- You need to compare, reverse or rebuild characters.
Say this before you type. Say which array pattern the string is hiding before you touch a character.
All 51 Strings problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.
Each locked part opens in the editor once the part before it passes.
Prep guides that list this problem
Our company tags come from public interview write-ups. None of these is a confirmed question.