Skip to content · ⁨Pular para o conteúdo⁩

Group anagrams · ⁨Agrupar anagramas⁩

English

Group anagrams

Two words are anagrams if they use exactly the same letters, like eat and tea. Group the anagrams together and return a list of groups.

The trick: sort the letters of each word to make a key — eat and tea both become aet. Words with the same key belong in the same group. Use a dictionary from key → list of words, and remember the order the keys first appear.

Português

Agrupar anagramas

Duas palavras são anagramas se usam exatamente as mesmas letras, como eat e tea. Agrupe os anagramas juntos e devolva uma lista de grupos.

O truque: ordenar as letras de cada palavra para criar uma chave — eat e tea tornam-se ambas aet. Palavras com a mesma chave pertencem ao mesmo grupo. Use um dicionário de chave → lista de palavras, e lembre-se da ordem em que as chaves aparecem primeiramente.

Log in or create account · ⁨Entrar ou criar conta⁩

IGCSE, A-Level & AP