Solution: Group Anagrams
Here's a detailed analysis on how to solve the Group Anagrams problem.
We'll cover the following...
Solution: using dictionary and list
Explanation
This solution sorts each input string in an ascending order, considers it as a key and the original string as the value of the corresponding key. It then checks if the key exists in a dictionary or not. If it doesn’t exist, it means it is occurring for the very first time, so it maps an empty list to the key and appends a value in it. If the key is already present, it simply appends the value to the list.
Now, each list in the dictionary has anagrams. In the end, it iterates over the dictionary and stores all the values in a list if, in the key-value pair, the value corresponding to the key is greater than 2. The resultant list is returned, which has the pair of anagrams.
Time complexity
Sorting one ...