Question bank › Prefix Sum
Dsa Prefix Sum Easy

Inventory Changes Summary

You need to track inventory changes for a product over a series of days. Each input will consist of an integer n representing the number of days followed by n integers denoting daily changes in inventory (can be positive or negative). Given several pairs of days, compute the net inventory changes for these ranges. Your input will consist of the number of days, the changes and the number of queries, each containing two integers for the range. For example: Input: 5 10 -5 2 3 -1 2 0 2 1 4 Output: 7 -1 The first query calculates the inventory change from day 0 to day 2 (10 - 5 + 2) which equals 7, while the second calculates from day 1 to day 4 (-5 + 2 + 3 - 1) which equals -1.

Key concepts

prefix_sumincrementbalance

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