Skip to content
Decoder

Group Anagrams

Medium

Problem

Given a list of words strs, put words that are anagrams of each other (same letters, same counts) into the same group. Return the list of groups. The order of the groups, and the order inside each group, does not matter.

Example 1

["eat", "tea", "tan", "ate", "nat", "bat"]

Example 2

  →  [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]

Example 3

Input
[""]
Output
[[""]]

Example 4

Input
["a"]
Output
[["a"]]

Constraints

  • 0 <= strs.length <= 10^4
  • 0 <= strs[i].length <= 100
  • strs[i] contains only lowercase English letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.