Group Anagrams
Try to solve the Group Anagrams problem.
Statement
Given a list of words or phrases, group the words that are anagrams of each other. An anagram is a word or phrase formed from another word by rearranging its letters.
Constraints:
Let strs
be the list of strings given as input to find the anagrams.
-
strs.length
-
strs[i].length
strs[i]
consists of lowercase English letters.
Note: The order in which the output is displayed doesn’t matter.
Examples
Understand the problem
Let’s take a moment to make sure you've correctly understood the problem. The quiz below helps you check if you're solving the correct problem:
Group Anagrams
What is the output if the following array is given as input?
[‘bat’, ‘tab’, ‘tan’, ‘at’]
[[‘at’], [‘bat’], [‘tab’], [‘tan’]]
[[‘at’, ‘bat’]], [[‘tab’, tan’]]
[[‘at’, ‘bat’, ‘tab’, tan’]]
[[‘tab’, ‘bat’]], [‘tan’], [‘at’]]
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
package mainfunc groupAnagrams(strs []string) [][]string {// Replace this placeholder return statement with your codereturn make([][]string, 0)}