medium
arrays
hashmap
heap
priority-queue
bucket-sort
Given integer array nums and integer k, return the k most frequent elements from highest to lowest frequency. The answer is guaranteed unique.
Examples
Example 1
Input: nums = [1,1,1,2,2,3], k = 2
Output: [1,2]
Example 2
Input: nums = [1], k = 1
Output: [1]
Example 3
Input: nums = [4,4,4,4,2,2,2,3,3,1], k = 3
Output: [4,2,3]
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.