Amazon Interview Question

Find top 10 occurring words in a page.

Interview Answers

Anonymous

Feb 23, 2014

Priority Queue

1

Anonymous

Jun 26, 2016

1. Create HashMap {word: value} 2. Insert every word to map with value 1, if it is already there increment its valu, by 1 3. Push map tuples to vector and sort by values, or push it to priority queue. 4. Extract ten highest keys. Time complexity: m - number of unique words n - number of all words O(n+mlog(m))