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
- 1 <= nums.length <= 10^5
- -10^4 <= nums[i] <= 10^4
- 1 <= k <= number of distinct values
- The answer is unique