Group Anagrams
Mediumjavapythonccppjavascript
Given a list of words, group together the words that are anagrams of each other.
Input Format
The first line contains an integer K, the number of words. Each of the next K lines contains one lowercase word with no spaces.
Output Format
Print one line per group. Within a group, keep the words in input order, separated by single spaces. Order the groups by the first appearance of any of their members.
Example 1
Input
6 eat tea tan ate nat bat
Output
eat tea ate tan nat bat
Explanation: Words with the same letter multiset are in one group.
- 1 <= K <= 10000
- 1 <= length of each word <= 100
- Words consist of lowercase English letters.