Given an array of strings, group anagrams together.


Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Output: [ [“ate”,”eat”,”tea”], [“nat”,”tan”], [“bat”] ]


All inputs will be in lowercase.

The order of your output does not matter.


To group Anagram words, We can sort all string with characters and match it with other string to verify if its anagram or not. We can use Map to group all equal strings.



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

We encourage you to write a comment if you have a better solution or having any doubt on the above topic.

Leave a Reply

Your email address will not be published. Required fields are marked *