Practice arena
C++17·2 s·128 MB
HeapsIntermediate
Running kth largest
After every stream value, print the kth largest value seen so far. Print -1 until at least k values have arrived.
Input
- — The first line contains T.
- — Each case contains n and k, followed by n non-negative stream values.
Output
Print n answers for each case.
Technique
size-k min heap
Target
O(n log k)
Constraints & sample
- 1 ≤ k ≤ n ≤ 200,000
- 0 ≤ value ≤ 10⁹
Sample input
2 6 3 4 5 8 2 10 9 4 2 3 1 5 12
Expected output
-1 -1 4 4 5 8 -1 1 3 5
Before you submit
- Test the smallest valid input and one awkward edge case.
- Keep the solution within O(n log k).
- Match spacing and line breaks exactly before checking 7 hidden cases.
Draft saved locally · 499 / 30,000
Ln 1, Col 1Spaces: 4UTF-8LFC++17
Visible testcases
Editable and stored only in this browser. Hidden judge cases never change.
Checking your session…
Run checks Sample · Submit checks 7 hidden cases
Run the sample first, then send your solution through 7 hidden cases.
Code runs in an isolated Judge0 environment. Drafts and custom visible cases stay on this device; submission metadata and progress sync to MongoDB.