Group Anagrams

Problem Given an array of strings, group together all strings that are anagrams of each other.

Input / Output

  • Input: array of strings strs.
  • Output: a list of groups, each containing mutually-anagram strings (any order).

Constraints

  • 1 ≤ n ≤ 10^4; strings are lowercase English letters.
  • Total input size can be large, so per-string work should stay near-linear.

Example

  • ["eat","tea","tan","ate","nat","bat"] → [["eat","tea","ate"],["tan","nat"],["bat"]]
added …
LeaderboardSalaryAccount