Loading...
Given an integer array nums and an integer k, return the k values that occur most frequently in nums.
Order the result by frequency, most frequent first. If two values occur the same number of times, the larger value comes first. This ordering makes the answer unique.
Input: nums = [1,2,2,3,3,3], k = 2
Output: [3,2]
Explanation: 3 occurs three times and 2 occurs twice, the two highest frequencies.
Input: nums = [4,4,7,7,1], k = 2
Output: [7,4]
Explanation: 4 and 7 both occur twice. They tie on frequency, so the larger value 7 comes first.
Input: nums = [5], k = 1
Output: [5]
nums.length ≤105nums[i] ≤104k ≤ the number of distinct values in nums.Click "Run" to test with sample cases or "Submit" to run all tests.