Algorithms and Data Structures · Middle · Question 55 of 75
What does the group anagrams problem usually use as a map key?
groupAnagrams(["eat", "tea", "tan", "ate", "nat"]);
// [["eat", "tea", "ate"], ["tan", "nat"]]- ✓Correct answer: The word's sorted letters or letter counts
- 2The first and the last letter of the word
- 3The length of the word in characters
Explanation
Anagrams share the same multiset of letters, so "aet" (sorted) is the same for eat, tea and ate. Length or first letter would put non-anagrams together.