# Leetcode 347 - Top K frequent elements

Note:

• Cannot use normal sort methods because of the limit of time complexity.
• Use bucket sort because its average time complexity is O(n).
• Use map to track the frequencies.
• Iterate map and assign num which has the same frequency to bucket[frequency].
• Iterate backwards and find k elements as the result.

Question:

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

Example:

Code: