Dsa
Heap
Medium
Dynamic Top K Scores with Stream
Design a system that continuously receives scores in a stream and can return the top K scores at any time. Implement the logic to handle this with a min-heap.
Input:
- The first line contains an integer K.
- The next lines contain integers representing scores. The input ends when a line contains 'end'.
Output:
- For each score received, if the total scores received so far is K or more, print the current top K scores.
Example:
Input:
2
80
90
70
end
Output:
90
80
Explanation: After receiving 90 and 80, the top 2 scores are printed, which are 90 and 80.
Key concepts
heapstreamingdynamic k
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