Skip to content

Group Anagrams

MediumArrays & Hashing
Decode it first. Clues, constraints, pattern and plan before any code.

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.

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

Constraints

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