Find the top K frequent elements in an array.
Unlock detailed company stats for this questionUpgrade
Given a non-empty integer array, return the k elements with the highest frequency. One solution is a HashMap of counts plus a min-heap of size k; another is bucket sort. Follow-ups: can the time complexity be better than O(N log N), and how can the space complexity be optimized?
Expect follow-ups like
- Solve it with in-place bottom-up heapify.
- Can the time complexity be better than O(N log N)?
- How can the space complexity be optimized?
Format · Screening round.
Also asked as · Find the top K frequent elements.
Community answers
No answers contributed by the community yet.
Related questions
Find the unique elements in an array.Find the K'th smallest element in an array.Top k frequent elementsRelated courses

Course

Course
Course


