Dsa
Heap
Easy
The Selective Logger
You are processing a stream of sensor readings (integers). At any point, a 'GET' command might be issued. You must output the K-th largest value seen so far. If fewer than K values have been received, output -1.
Example:
K=2. Stream: 10, 20, GET, 5, 30, GET.
- 10 received.
- 20 received.
- GET: 2nd largest is 10.
- 5 received.
- 30 received.
- GET: 2nd largest is 20.
Output: 10 20 (on separate lines).
Key concepts
heapstreamingkth-element
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now