Group Anagrams
Medium Sorting AI round
strs is a list of words, each made of lowercase letters. A word may be empty, and the same word may appear more than once.
Two words are anagrams when they hold exactly the same letters, each letter the same number of times. Put every word of strs into a group with its anagrams, so that each word is in exactly one group, and two words that are not anagrams are never in the same group.
Return the groups, each as a list of its words. The groups may come in any order, and so may the words inside each group.
Example 1
spare, pears and reaps are made of the same five letters, and so are cat, act and tac. bold has no anagram in the list, so it is a group of one.
Example 2
Example 3
Constraints
1 ≤ strs.length ≤ 80000 ≤ strs[i].length ≤ 30strs[i]holds only the lettersatoz
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
Your first AI round is free.
Watch the explanation
More Sorting
- Contains DuplicateAI round · Easy
- Maximum GapAI round · Medium
- Valid AnagramEasy
- Majority Element IIMedium
- Find All Duplicates in an ArrayMedium