DIY: Group Anagrams

Solve the interview question "Group Anagrams" yourself in this lesson.

We'll cover the following

Problem Statement

You are given an array of words or phrases, and you need to group the words that are anagrams of each other. An anagram is a word, phrase, or sentence formed from another word by rearranging its letters.


The input will be an array of words or phrases. The following is an example of input:

["word", "sword", "drow", "rowd", "iced", "dice"]


The output should be an array of grouped words. The following is an example output:

[['word', 'drow', 'rowd'], ['sword'], ['iced', 'dice']]

Coding exercise

You need to implement the function groupAnagrams(strs), where strs is the array of words you need to group together. The function returns an array containing multiple lists of the newly created groups.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy