Question bank › Prefix Sum
Dsa Prefix Sum Easy

Bank Transaction Analysis

A bank wants to analyze the transactions over a number of days to find the total net balance change between any two specific days. Write a program that processes a list of daily transaction amounts (positive for deposits, negative for withdrawals) and allows querying of net changes over arbitrary day ranges. Input format: - The first line contains an integer D (1 ≤ D ≤ 100,000), the number of days. - The second line contains D integers, representing daily transaction amounts. - The third line contains two integers, startDay and endDay (0 ≤ startDay ≤ endDay < D), the range of days for the query. Output format: - Output a single integer: the total balance change from startDay to endDay (inclusive). Example: Input: 5 100 -50 200 -30 50 1 3 Output: 120

Key concepts

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