Return the k most frequent elements of nums in any order.
k
nums
The answer is guaranteed to be unique.
nums = [1,1,1,2,2,3], k = 2
[1,2]
nums = [1], k = 1
[1]
1 <= nums.length <= 10^5 k is in the range [1, number of distinct elements]
Topics
Implement topKFrequent in the editor and return the answer — printing it is never graded.
topKFrequent
Problem 73 of 1146 in the arena