52. K Most Frequent Values
Medium
Return the k most frequent values in descending order of frequency. In case of a tie, the smaller value comes first.
Example 1
Input: nums = [4,4,2,2,2,7,4,9], k = 2
Output: [2,4]
Example 2
Input: nums = [8,3,3,8], k = 2
Output: [3,8]
Constraints
- 1 <= nums.length <= 10000
- 1 <= k <= quantidade de valores distintos
ArraysHash mapSorting
Saved in this browser
Caso 1
nums =
[4,4,2,2,2,7,4,9]
k =
2
Expected =
[2,4]
Caso 2
nums =
[8,3,3,8]
k =
2
Expected =
[3,8]
Run checks these 2 cases. Submit runs all 6, including hidden ones.