Arrays & HashingMedium
Top K Frequent Elements
Return the k numbers that appear most often in nums, in any order. The answer is always unique.
Example 1nums = [7, 7, 7, 3, 3, 9], k = 2 → [7, 3]
Example 2nums = [4], k = 1 → [4]
1 ≤ n ≤ 10⁵ · 1 ≤ k ≤ number of different values