Group Anagrams
Problem statement
Implement groupAnagrams for the classic Group Anagrams problem.
This Blind 75 version is framed for frontend interviews: write clean JavaScript, name the invariant out loud, and handle edge cases without over-engineering.
What this tests
- Pattern:
canonical key grouping. - Ability to explain time and space complexity clearly.
- Careful handling of empty inputs, duplicates, and boundary cases.
- Production-style JavaScript readability, not just competitive-programming shortcuts.
Requirements & constraints
- Use JavaScript without external libraries.
- Prefer the standard optimal interview approach for this pattern.
- Return deterministic output when multiple valid outputs exist where the prompt implies ordering.
Examples
Example 1
Input: Use the canonical Blind 75 sample for this problem.
Output: Return the value required by the problem statement.
How to approach Group Anagrams
The strategy an interviewer expects you to reach for.
Group words that are anagrams of each other — map from a canonical key to a bucket list. Naive move Compare every word to every other word. Where it breaks Quadratic compares. Sorting each word as a key is the usual fix. The fix For each word, sort characters (or count letters) into a key; push into Map[key]. Dry-run: Example: ["eat","tea","tan"] → key "aet" buckets eat/tea; "ant" buckets tan. Remember: Canonical key → list. Sorting letters is the simplest key. Say this in the interview: I'd key each word by its sorted characters and group words that share that key in a Map.
The full solution is part of HelloFrontend Pro
The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.
- Runnable editor with the hidden test suite
- Progressive hints that unlock as you get stuck
- Senior-level reference solution with a line-by-line walkthrough
Already a member? Log in to open the workspace.