Skip to interview prep
Apexed

72. Group Anagrams

MediumHashing

Group the words in words that are anagrams of each other. Sort the words inside each group, and order the groups by their first word.

Example 1

Input: words = ["eat", "tea", "tan", "ate", "nat", "bat"]
Output: [["ate", "eat", "tea"], ["bat"], ["nat", "tan"]]

Constraints

  • 1 ≤ words.length ≤ 10⁴

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 3 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Group Anagrams — coding interview practice — Apexed