Given an array of strings or a list of words, write a code to group anagrams together.
what are Anagrams?
Two strings are said to be anagrams of each other if it contains the same characters, only the order of character in both the strings is different.
Check whether two strings are anagrams of each other or not
For example, Word “car” and “rac” are anagrams of each other. As both, the strings contain the same number of characters only the order of character is different in both the strings.
Now, let’s understand this problem statement with example.
For example:
Input: {“eat”, “tea”, “tan”, “ate”, “nat”, “bat”}
Output:
1 2 3 4 5 |
[ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] |