Dsa
Prefix Sum
Easy
Game Score Tracking
In a competitive game, players earn points over multiple rounds. Given an array that represents the points earned in each round, your task is to answer several queries about the total points earned within specified rounds.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000) - the number of rounds.
- The second line contains n space-separated integers representing points earned in each round (0 ≤ points[i] ≤ 100).
- The third line contains an integer q (1 ≤ q ≤ 10) - the number of queries.
- The following q lines contain two integers l and r (1 ≤ l ≤ n) representing the range of rounds.
Output format:
- For each query, print the total points earned in that range on a new line.
Example:
Input:
6
10 20 15 5 25 30
3
1 3
2 5
1 6
Output:
45
70
105
Key concepts
prefix_sumscoreaggregation
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