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"]]

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.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 55

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz