Medium30 pts
Group Anagrams
Given an array of strings, group the anagrams together. Anagrams are words with the same characters in different order. Algorithm: Sort each word's characters and use as key in a hash map. Example: ['eat','tea','tan','ate','nat','bat'] → Groups: ['eat','tea','ate'], ['tan','nat'], ['bat']
Input
Line 1: n (number of words). Line 2: n space-separated words.
Output
Each group on a line, words space-separated, groups sorted alphabetically by first word, words within groups sorted.
Sample
6 eat tea tan ate nat bat
Expected
ate eat tea bat nat tan
Loading editor…
Output
No output yet. Run your code to see results.