Question bank › Prefix Sum
Dsa Prefix Sum Easy

Temperature Range Query

You are given the daily temperatures in a week. Each temperature value is represented as an integer. You need to answer multiple queries about the sum of temperatures over specified days. For each query, you will be given the start and end days (inclusive) to find the sum of temperatures. Input format: - The first line contains an integer n (7). - The second line contains 7 space-separated integers representing daily temperatures. - The third line contains an integer q (1 ≤ q ≤ 10) - the number of queries. - The following q lines each contain two integers l and r (1 ≤ l ≤ r ≤ 7). Output format: - For each query, print the sum of temperatures for that range on a new line. Example: Input: 7 22 23 21 20 19 18 24 3 1 3 2 6 1 7 Output: 66 102 127

Key concepts

prefix_sumqueryrange_sum

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.