347. Top K Frequent Elements

Practice Top K Frequent Elements for free on NudgeCode: Medium, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return the k values that occur most often in nums, in any order. The inputs are chosen so the answer is unique. Try to beat O(n log n).

Example

nums = [1,1,1,2,2,3], k = 2  ->  [1,2]

Constraints