Anagram Groups

Hashmap Anagrams Strings

Anagram Groups

Given an array of strings, group the strings that are anagrams of each other. An anagram is a word formed by rearranging the letters of a different word, using all the original letters exactly once.

For example, given the input:

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

One possible output is:

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

Instructions:

  • Use a hashmap (or dictionary) to efficiently group the anagrams together.
  • The order of the groups or the order of strings inside a group is not important.
  • Consider using sorted string as a key in your hashmap.

Holiday Tie-in:

As the winter holidays approach, enjoy rearranging words as you rearrange your holiday decorations! Just as each unique arrangement creates a new festive feel, every anagram group tells its own unique story.