Loading practice problems…
Loading your practice workspace…
Loading code editor…
3 / 29
Sign in
Algorithms/Frequency Counter

Group Anagrams

medium30 min

Given an array of lowercase strings, group the strings that are anagrams of one another.

Return groups in the order their character signature first appears, and keep words inside each group in input order.

Example 1

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

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

Example 2

Inputwords = ["a"]

Output[["a"]]

Constraints

  • 1 ≤ words.length ≤ 10,000
  • Every word contains lowercase English letters.
Frequency CounterHash MapStrings