S
All challenges
Practice
Home
Blog
Practice
Examples
Feedback
Top K Frequent Elements
00:00
Start
00:00
Sign in
Problem
Hints
3
Solution
History
Medium
Array
HashMap
Heap
Bucket Sort
Amazon
Facebook
Find the k most frequent elements in an array. Return them in any order.
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,1,2,4,2,1,1], k=2
Output →
[1,4]
JavaScript
Python
Java (Coming soon)
C (Coming soon)
C++ (Coming soon)
Reset
Run
Submit
Cases
Results