Range Addition Problem
Range Addition Problem — ExecCode Medium DSA Practice
Solve the Range Addition 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
You are given the integer length of an array (initialized to all zeros) and a list of update triples [startIdx, endIdx, inc]. Each update adds inc to every element from startIdx to endIdx inclusive. Return the array after applying all updates.
Examples
Input length = 5, updates = [[1, 3, 2], [2, 4, 3], [0, 2, -2]]; Output [-2, 0, 3, 5, 3]. Input length = 6, updates = [[1, 3, 2], [2, 4, 3], [0, 2, -2], [4, 5, 1]]; Output [-2, 0, 3, 5, 4, 1]. Input length = 4, updates = [[0, 3, 1]]; Output [1, 1, 1, 1]
Constraints
1 ≤ length ≤ 10⁵ 0 ≤ updates.length ≤ 10⁴ 0 ≤ startIdx ≤ endIdx < length -1000 ≤ inc ≤ 1000
Practice Range Addition free on ExecCode. Browse DSA problems, topic map, and placement guides.