Problem
Given a list of integers nums and a number k, return the **k values that appear most often**. You can return them in any order. Aim for better than O(n log n).
Example 1
- Input
- nums = [1, 1, 1, 2, 2, 3], k = 2
- Output
- [1, 2]
Example 2
- Input
- nums = [4, 4, 4, 6, 6, 5], k = 1
- Output
- [4]
Example 3
- Input
- nums = [1], k = 1
- Output
- [1]
Constraints
1 <= nums.length <= 10^5-10^4 <= nums[i] <= 10^41 <= k <= the number of distinct values.The answer is unique: there is no tie at the cut-off.