Dsa
Prefix Sum
Warm-up
Transaction Balancing
In a financial tracking app, you need to balance expenditures over a week. You will be given the net balance amount for each day and need to report the total balance up to any day. Write a program that reads the net balances for 7 days and answers multiple queries regarding total balance by day. For example, given the input:
7
100 -50 200 -100 50 25 75
4
1 2 5 7
You should output:
100
50
50
125
This is because the cumulative balances for day 1, day 2, day 5, and day 7 are 100, 50, 50, and 125 respectively.
Key concepts
prefix_sumarrayscumulative_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