Prerequsites : kth smallest element in an array, K closest Point to Origin
These questions involve finding the Kth superlative element. However, we can't sort values directly. Instead, we calculate a value to determine their order, such as distance or frequency, and use that value to sort them. We can then return the Kth corresponding element. The unique characteristic of these questions is that we use the first element in the payload to determine the sortedness across the heap.
Questions
- K closest Point to Origin and Find K Closest Elements: use a formula to calculate distance and sort across distance
- Top K Frequent Elements and Top K Frequent Words: use a hashmap to determine frequency and then sort across the frequency.
- You will be required to add a payload in subsequent questions in this roadmap. The first item in the heap is used to determine the sordidness of the heap. We will discuss these question in the further modules. Examples include