Question bank › Prefix Sum
Dsa Prefix Sum Medium

Range Sum Queries

You are given an integer array `nums` and a list of queries. Each query consists of two integers `L` and `R`, and you need to find the sum of the elements in the range from index `L` to `R` (inclusive). Write a program that takes the array and the queries, and prints the sum for each query. Input format: - The first line contains an integer `n`, the number of elements in the array. - The second line contains `n` space-separated integers representing the elements of the array `nums`. - The third line contains the integer `q`, the number of queries. - The next `q` lines contain two integers `L` and `R` (0-indexed). Output format: - Output `q` lines, each containing the sum for the corresponding query. Example: Input: 5 2 4 6 8 10 2 0 2 1 4 Output: 12 38

Key concepts

prefix_sumrange_query

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.