Range Sum Query (range add) Problem
Range Sum Query (range add) Problem — ExecCode Medium DSA Practice
Solve the Range Sum Query (range add) problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an integer array nums, a list of range-add updates [l, r, val] to apply on top of it, and a list of sum queries [l, r], apply all updates first using a difference array, then answer each query with the sum of the final array over that inclusive range.
Examples
Input nums = [1, 2, 3, 4, 5, 6], updates = [[0, 2, 1], [1, 3, 2], [2, 5, 1]], queries = [[0, 5], [1, 3]]; Output [34, 19]. Input nums = [1, 1, 1, 1], updates = [[0, 3, 1]], queries = [[0, 3]]; Output [8]. Input nums = [5, 5, 5], updates = [], queries = [[0, 2], [1, 1]]; Output [15, 5]
Constraints
1 ≤ nums.length ≤ 10⁴ 0 ≤ updates.length, queries.length ≤ 10⁴ 0 ≤ l ≤ r < nums.length -1000 ≤ val, nums[i] ≤ 1000
Practice Range Sum Query (range add) free on ExecCode. Browse DSA problems, topic map, and placement guides.