The Top K frequent elements is one of the many problems in Leetcode that involve hashing, and is also one of the first Medium challenge found in Neetcode, specifically when you start at the Arrays & Hashing section in the roadmap.
It states that given an array of integers and an integer k, create a function that returns the k most frequent integers.
It sounds easy enough, but the Dunning-Kruger effect got me once again. So, I opened the Hints section. It told me that the ideal solution must be O(n), and an algorithm that involves sorting based on frequency is applied to it. Google then led me to the Bucket Sort Algorithm.
From my understanding, the Bucket Sort Algorithm is well, an algorithm that is used to partition an input array into smaller arrays, assigning an element into an element array (or in this case, buckets).
After lots of syntax error and wrong outputs, here is what I came up with.






