Search for a command to run...
Problem Statement:
Given an integer array nums and an integer k, return the k most frequent elements.
You may return the answer in any order.
Input
nums = [1, 1, 1, 2, 2, 3]
k = 2
Output
[1, 2]
Explanation:
Element 1 appears 3 times, 2 appears 2 times, and 3 appears once.
The two most frequent elements are 1 and 2.
nums.length β€ 10β΅nums[i] β€ 10β΄k β€ number of unique elementsExample 1
[5, 2, 5, 3, 5, 3, 1, 1, 3], 2[5,3]Example 2
[7, 7, 7, 6, 6, 5, 5, 5, 5], 2[5,7][5, 2, 5, 3, 5, 3, 1, 1, 3], 2
[5,3]