← All problems

Group Anagrams

Medium stringshash maps LeetCode ↗
Given an array of strings, group all anagrams together and return the groups in any order. Two strings are anagrams if one can be rearranged into the other. Optimize beyond pairwise comparison.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n*k), Space O(n*k)

Common pitfalls

  • Using the sorted string when k is huge
  • Mutating the key

Your solution

Log in to save your code and track progress.