Question bank › Prefix Sum
Dsa Prefix Sum Easy

Game Scores

You are managing scores from a series of games. Each game results in a score that can increase or decrease. You need to compute the total score over specific game intervals. Write a function that reads the number of games and their respective scores, followed by a series of queries. Each query consists of a start and an end index indicating which games' scores to sum. Input: The first line contains an integer n (1 ≤ n ≤ 10^5), the number of games. The second line contains n space-separated integers representing the scores for each game. The third line contains an integer q (1 ≤ q ≤ 10^5), the number of queries. The following q lines each contain two space-separated integers, start and end (1 ≤ start ≤ end ≤ n). Output: For each query, output the total score for the specified game interval. Example: Input: 4 5 -3 7 2 2 1 2 2 4 Output: 2 6

Key concepts

prefix_sumscore_tracking

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.