Pergunta de entrevista da empresa Yelp

Implement this anagram grouping algorithm with a running time of O(n).

Respostas da entrevista

Sigiloso

22 de mai. de 2014

For each letter of the alphabet you could assign each letter a unique prime number, then for each word you would calculate the product of each prime number/letter in the word. This will result in a unique number that you could put into a hash table that contained a list of words that got entered under that product, then you would just dump the table.

5

Sigiloso

6 de out. de 2014

This maybe more than O(n) but it is the best I solution I have for now. Sort your inputs and use trie. Each time you encounter a word twice, put that word in a list.