Group Anagrams

Medium
ArrayHash TableStringSortingAmazonMeta
Given a list of lowercase words, group words that are anagrams of each other. Input format: - First line: n - Next n lines: one word per line Sort words inside each group alphabetically. Sort groups by their first word. Print one group per line with words separated by spaces.

Constraints

1 <= n <= 10^4
1 <= word length <= 100
Words contain lowercase English letters.

Sample tests

Sample 1

Sample 2

Sign in to submit