Question bank › Prefix Sum
Dsa Prefix Sum Warm-up

Total Inventory Tracking

For a small business, you are tracking the total inventory over a series of days. Each day, a certain number of items are added or removed. Write a program that reads the net change in inventory for 7 days and allows querying the total inventory up to any day. For instance, given the input: 7 20 -5 15 -10 30 -20 10 3 2 5 7 You should output: 15 50 10 This is because the cumulative inventory for day 2, day 5, and day 7 are 15, 50, and 10 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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.