Interview Questions

203. Given an integer array. Find the five most frequent numbers.

Microsoft Interview Questions and Answers


(Continued from previous question...)

203. Given an integer array. Find the five most frequent numbers.

Question:
Given an integer array. Find the five most frequent numbers.


maybe an answer:


Option 1: Use hashtable and min heap. Anytime you read a number update its frequency in hash table. Then insert it in min heap. If min heap's size is greater than 5, then pop the minimum number.

Option 2: Use hashtable to store numbers and their frequencies. Then sort by frequencies using radix sort and pick 5 numbers from bottom.

(Continued on next question...)

Other Interview Questions