Question bank › Heap
Dsa Heap Easy

Grid Power Optimizer

You are managing a local power grid. Sensors provide real-time power readings from various sources. You need to report the total power generated by the top K most productive sources every time a new sensor reading is added. If there are fewer than K sources, sum all of them. Input Format: - The first line contains two integers: K (the number of top sources to track) and N (the total number of sensor readings). - The next N lines each contain a single integer representing a power reading from a new source. Output Format: - N lines, where each line is the sum of the K largest readings received so far. Example: Input: 2 4 10 20 5 30 Output: 10 30 30 50 (Explanation: 10 -> [10] sum 10; 20 -> [20, 10] sum 30; 5 -> [20, 10] sum 30; 30 -> [30, 20] sum 50)

Key concepts

heapstream processing

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.