We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
A medium heap / priority queue problem, graded against 6 test cases (3 of them hidden).
A priority queue for "top k" and streaming-median questions.
Reach for it when you see: "Top/smallest k", a running median, or repeatedly needing the current minimum.
More Heap / Priority Queueproblems →Maintain a min-heap of size k. The root is the kth largest.
Solution 2: Quickselect
Partition around a pivot until we find the kth largest position.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.