Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Introduction to Top 'K' Elements Pattern
Any problem that asks us to find the top/smallest/frequent ‘K’ elements among a given set falls under this pattern.
The best data structure that comes to mind to keep track of ‘K’ elements is Heap. This pattern will make use of the Heap to solve multiple problems dealing with ‘K’ elements at a time from a set of given elements.
Let’s jump onto our first problem to develop an understanding of this pattern.
.....
.....
.....
Like the course? Get enrolled and start learning!
Miguel
· 2 years ago
After going through this section, I feel it might be helpful to put the Pattern: Two Heaps after Patter: Top K Elements . This section is quite heavy with heaps and builds a lot of intuition on when to use minHeaps vs maxHeaps.