Question bank › Prefix Sum
Dsa Prefix Sum Easy

Cumulative Temperature Changes

You are given a list of daily temperature changes as integers, where a positive number means an increase in temperature and a negative number means a decrease. Write a program that determines the total temperature change over a specific range of days defined by two indices. Your program should read the number of days, the temperature changes, and the indices, and output the total temperature change for that range. Input format: - The first line contains an integer N (1 ≤ N ≤ 100,000), the number of days. - The second line contains N integers, representing the temperature changes. - The third line contains two integers, L and R (0 ≤ L ≤ R < N), the indices defining the range. Output format: - Output a single integer: the total temperature change from day L to day R (inclusive). Example: Input: 7 5 -2 -1 3 4 0 -3 2 5 Output: 3

Key concepts

prefix_sumarray_manipulation

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 InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.