Return the k most frequent numbers from a list, in any order.
Constraints
Example
```python # Example 1 nums = [1,1,1,2,2,3] k = 2 print(top_k_frequent(nums, k)) # Output: [1, 2] (any order) # Example 2 nums = [1] k = 1 print(top_k_frequent(nums, k)) # Output: [1] # Example 3 nums = [4,4,4,5,5,6,6,6,7] k = 3 print(top_k_frequent(nums, k)) # Output could be [4, 6, 5] (any order) ```
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints