Due to the limited space of the post, we will mention each category. If you want to dig deeper and have enough time, you can sign up for my class. I have summarized ten categories of adaptation questions, and each category has multiple adaptation cases. Let’s go back to one last example of an adaptation of hashes, and let’s talk about Array and Linked List, the brothers who love each other so much.

Let’s look at an example of a hash table:

As usual, first to the original question:

Given an array of strings all isomorphic words are grouped together. Ex. :

[“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],

Returns:

[

[“ate”, “eat”,”tea”],

[“nat”,”tan”],

[“bat”]

]

Explanation: If two words have exactly the same letters in different places, we call them anagrams.

So first of all, let’s do a cool analysis, because we’re using a hash table, we have to have an element that’s good for a key. So if you need to find the right key, how do you do it? Let’s observe that “tea” and “ate” are only different in order. Eventually these two words can be mapped to the same “isomorphic word”, which is our group requirement. To put anagrams together, we put the letters in order before each hash so that all anagrams will have the same hash value. We’re going to use string as the key, but we’re going to use the result of sorting the key as the key.