Question bank › Prefix Sum
Dsa Prefix Sum Easy

Daily Expense Tracker

A personal finance application tracks daily expenses and allows users to query their total expenses over any given period. Write a program to compute total expenses between two specified days. Input format: - The first line contains an integer E (1 ≤ E ≤ 100,000), the number of days tracked. - The second line contains E integers, representing the expenses for each day (can be negative for refunds). - The third line contains two integers, startDay and endDay (0 ≤ startDay ≤ endDay < E), the range of days for the expense query. Output format: - Output a single integer: the total expenses from startDay to endDay (inclusive). Example: Input: 5 50 20 -10 40 100 1 4 Output: 250

Key concepts

prefix_sumrange_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.