Question bank › Prefix Sum
Dsa Prefix Sum Easy

Subarray Sales Sum

A store wants to analyze its sales data for a month. Given an array of integers representing daily sales, determine the total sales for any given range of days. You will be provided a list of queries, each consisting of two integers representing the start and end of the range (inclusive). Print the total sales for each query. Input format: - The first line contains an integer n (1 ≤ n ≤ 2 * 10^5) - the number of days. - The second line contains n space-separated integers representing the daily sales (1 ≤ sales[i] ≤ 10^4). - The third line contains an integer q (1 ≤ q ≤ 100) - the number of queries. - The following q lines contain two integers l and r (1 ≤ l ≤ r ≤ n) for each query. Output format: - For each query, print the total sales in that range on a new line. Example: Input: 5 20 30 50 10 40 3 1 3 2 5 1 5 Output: 100 120 150

Key concepts

prefix_sumsubarrayaccumulation

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.