You are given an array of integers nums.
Your task is to find the k values that appear the most frequently in the array.
The result can be returned in any order.
If multiple numbers have the same frequency, any of them may appear in the result, as long as exactly k values are returned.
Input: nums = [4,4,4,5,5,6], k = 2
Output: [4,5]
Explanation:
4 appears 3 times, 5 appears 2 times, and 6 appears once → Top 2 are 4 and 5.
Input: nums = [9,9,8,8,7,7], k = 3
Output: [7,8,9]
Explanation:
All appear exactly twice → any order is valid.
Input: nums = [10], k = 1
Output: [10]
Explanation:
Only one number exists.
Accepted:
Submission: