ASAPUtils Logo ASAPUtils
Week 1

Top K Frequent Elements

Top K Frequent Elements in O(n) with bucket sort, plus the heap and sorting alternatives, C++ and JavaScript solutions, and why counting bounds the buckets at exactly n.

The problem

Given an integer array and an integer k, return the k most frequent elements. You may return the answer in any order, and the answer is guaranteed to be unique.

nums = [1,1,1,2,2,3], k = 2 -> [1, 2]

Related Problems