Pergunta de entrevista da empresa Amazon

Return top 10 most used words in a string

Respostas da entrevista

Sigiloso

12 de dez. de 2011

Go through every word, and put the count of each word in a hashmap. That will be O(n). Then for every key in the Hashmap you get it's count and you can use different sorting algorithms to determine the order. (for example you could put everything into a heap, binary search tree, use bin sort, or use insertion sort which works fast for streaming input).

Sigiloso

15 de mar. de 2012

Use a queue with size 10. Then put every word into a hashmap and check its count. If it's the max count, put it into the queue. (If this word already exists in the queue, put it at the end of the queue). Finally return the 10 words inside the queue.