Dsa
Prefix Sum
Warm-up
Aggregate Weather Data
You are given a list of daily temperature changes for a week and you need to find the accumulated temperature from day 1 to any given day. Write a program that reads the temperature changes for 7 days and provides the cumulative temperature for given queries about certain days. For example, given the input:
7
10 -3 5 2 -1 -2 4
3
1 4 7
You should output:
10
12
10
This is because the cumulative temperatures for day 1, day 4, and day 7 are 10, 12, and 10 respectively.
Key concepts
prefix_sumcumulative_sumarrays
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