Dsa
Prefix Sum
Warm-up
Healthy Living Calories
You are tracking the calories consumed by a group of individuals over a week. You want to know the total calories consumed up to certain days. Write a program that reads the total calorie intake for 7 days and returns the cumulative calorie counts for the specified days. For example, given the input:
7
500 600 300 400 700 300 800
3
1 3 5
You should output:
500
1400
2400
This is because the cumulative calories for day 1, day 3, and day 5 are 500, 1400, and 2400 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