Back to DSA
Top K Frequent Elements
mediumGiven an array of integers and an integer k, identify the k elements that appear most frequently. The result may be returned in any order.
Examples
Example 1:
Input:
nums = [3,3,3,1,1,2], k = 2Output:
[3,1] Example 2:
Input:
nums = [7], k = 1Output:
[7]Hints
1234567