Pregunta de entrevista de Expedia Group

How to find K most frequently occurring elements.

Respuestas de entrevistas

Anónimo

16 mar 2015

Using a hash table based mechanism

2

Anónimo

14 dic 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

Anónimo

9 mar 2019

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