Given an integer array `nums` and an integer `k`, return the `k` most frequent elements. You may return the answer in any order.
Bucket Sort (O(n))
Instead of sorting by frequency (which is $O(n log n)$), we can use Bucket Sort. We first count the frequencies of all elements using a hash map. Then, we create an array of buckets where the index represents the frequency. Each bucket contains a list of numbers that have that frequency. Finally, we iterate through the buckets from highest frequency to lowest and collect the first $k$ elements.