Solución
solution.tsTypeScript
export function groupAnagrams(words: string[]): string[][] {
if (!words.length) return []
const map = new Map<string, string[]>()
for (const word of words) {
const key = word.split('').sort().join('')
if (!map.has(key)) {
map.set(key, [])
}
map.get(key).push(word)
}
const result: string[][] = []
for (const group of map.values()) {
group.sort()
result.push(group)
}
result.sort((a, b) => a[0].localeCompare(b[0]))
return result;
}0respuestas