Dsa
Prefix Sum
Easy
Product Review Scores
You have a list of product review scores for the past week. Your task is to answer several queries about the total scores within specific ranges. You will receive an integer n representing the number of days (and thus scores) followed by n integers for review scores. Next, you will get an integer q which is the number of queries, followed by q pairs of integers representing the range of days to sum. For example:
Input:
6
4 5 3 2 1 0
3
0 1
2 5
1 4
Output:
9
6
11
This means the total score from day 0 to 1 is 4 + 5 = 9, from day 2 to 5 is 3 + 2 + 1 + 0 = 6, and from day 1 to 4 gives 5 + 3 + 2 + 1 = 11.
Key concepts
prefix_sumsubarraysum
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