Expedia Group Interview Question

How to find K most frequently occurring elements.

Interview Answers

Anonymous

Mar 16, 2015

Using a hash table based mechanism

2

Anonymous

Dec 14, 2015

Maintain hashmap with count of each element, and keep on adding elements to min heap, till heap has less than k elements. When heap is of size k, if next element count is greater than count of root element of min heap, remove root of min heap and add this new element. When all elements has been processed, heap will contain k most frequent elements

Anonymous

Mar 9, 2019

creating a frequency map and then using bucket sort is a pretty cool solution too. Runs in linear time.