Dsa
Prefix Sum
Easy
Energy Consumption Tracker
As an energy manager, you track hourly energy consumption changes. Write a program that reads the number of hours followed by the consumption changes for each hour (which can be positive or negative). Calculate and print the total consumption. If total consumption is less than zero, print 'Energy Surplus' instead of the total.
Example Input:
6
3
-1
-2
1
4
-5
Example Output:
Energy Surplus
Key concepts
prefix_sumarraycumulative_sum
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