Basic grouping
Input
['eat', 'tea', 'tan', 'ate', 'nat', 'bat']
Output
[['ate', 'eat', 'tea'], ['bat'], ['nat', 'tan']]
eat, tea, and ate are anagrams -> sorted -> ['ate','eat','tea']; tan and nat -> ['nat','tan']; bat alone.
Full lesson preview
Group a list of words into anagram groups using hashing for efficient grouping.
Problem statement
Task
Examples
Input
['eat', 'tea', 'tan', 'ate', 'nat', 'bat']
Output
[['ate', 'eat', 'tea'], ['bat'], ['nat', 'tan']]
eat, tea, and ate are anagrams -> sorted -> ['ate','eat','tea']; tan and nat -> ['nat','tan']; bat alone.
Input format
Output format
Constraints
Samples
Input
['a']
Output
[['a']]
Single word forms one group.