Group Anagrams
medium⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
6
eat tea tan ate nat bat
Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
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']
Formato de entrada
Line 1: n (number of words). Line 2: n space-separated words.
Formato de salida
Each group on a line, words space-separated, groups sorted alphabetically by first word, words within groups sorted.
Restricciones
1 ≤ n ≤ 10⁴, 0 ≤ word.length ≤ 100, words are lowercase letters