Group Anagrams
Given an array of strings strs, group the anagrams together.
You may return the answer in any order.
An anagram is a word formed by rearranging the letters of another word using all the original letters exactly once.
Example 1
Input
6 eat tea tan ate nat bat
Output
eat tea ate tan nat bat
Explanation
The strings "eat", "tea", and "ate" are anagrams.
The strings "tan" and "nat" are anagrams.
The string "bat" has no other anagram in the array.
Example 2
Input
1 a
Output
a
Explanation
There is only one string in the array, so it forms its own anagram group.
Constraints
Hints:
Hint 1
Words that are anagrams become identical after sorting their characters.
Hint 2
Use a hash map where the key is the sorted version (or character frequency) of a word, and the value is the list of words sharing that key.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 5, 2026
Last updated
Aug 9, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output