Easy · Size-k Min-Heap
Understand → Visualise → Practice.
A min-heap of size k keeps the current k largest values. Its root is the smallest among them: exactly the kth largest overall.
Push each value and remove the minimum whenever the heap grows beyond k.
Add the next value.
If size > k, pop the minimum.
After all values, heap[0] is kth largest.
O(n log k) time and O(k) space.
A min-heap, not a max-heap, makes it cheap to discard values below the top k.
Read the full guide first: Heaps and Priority Queues.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.