#339 Grouping Anagrams

Companies:
Avangard
Themes:
AlgorithmsStringsPractice

An array of strings strs is given. Group the anagrams together.

The answer may be returned in any order.

Example 1

Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]

Explanation

There is no string in strs that can be rearranged to form "bat".

The strings "nat" and "tan" are anagrams because their characters can be rearranged to form each other.

The strings "ate", "eat", and "tea" are anagrams because their characters can be rearranged to form each other.

Example 2

Input: strs = [""]
Output: [[""]]

Example 3

Input: strs = ["a"]
Output: [["a"]]

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in