Question bank › Prefix Sum
Dsa Prefix Sum Easy

Expense Tracker Query

Imagine you're building a finance application that tracks daily expenses. You're provided with daily expenses over a month (30 days) and need to calculate total expenses for specific day ranges based on user queries. The input consists of the number of days (30), followed by their respective daily expenses, and then multiple queries specifying ranges. For example: Input: 30 30 35 40 25 30 20 10 50 60 70 55 50 45 40 35 30 25 20 15 10 5 0 10 5 15 20 25 30 35 10 15 3 0 5 10 15 5 29 Output: 150 270 600 The first query calculates total expenses from day 0 to day 5 (30 + 35 + 40 + 25 + 30 + 20 = 150), the second from day 10 to day 15 (55 + 50 + 45 + 40 + 35 + 30 = 270) and the third encompasses all days from 5 to 29.

Key concepts

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