Dodomeki
Sign in

48. Group Anagrams

Medium

Receive a list of words and group those that are anagrams of each other. Return the groups in lexicographic order by the first word of each group; within each group, sort the words lexicographically.

Example 1
Input: palavras = ["roma", "amor", "casa", "ramo", "saca"]
Output: [["amor", "ramo", "roma"], ["casa", "saca"]]
Explanation: The words in the group share the same letters.
Example 2
Input: palavras = ["sol", "lua"]
Output: [["lua"], ["sol"]]
Constraints
  • 0 <= palavras.length <= 1000
  • Each word contains only lowercase letters and has up to 30 characters.
StringsHash map
Caso 1
palavras =
["roma","amor","casa","ramo","saca"]
Expected =
[["amor","ramo","roma"],["casa","saca"]]
Caso 2
palavras =
["sol","lua"]
Expected =
[["lua"],["sol"]]

Run checks these 2 cases. Submit runs all 6, including hidden ones.