Skip to content

Range Addition

MediumIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

Start with an array of length zeros. Each update [start, end, inc] adds inc to every element from index start to index end, inclusive (indices are 0-based). Apply all updates and return the final array.

length = 5, updates = [[1, 3, 2], [2, 4, 3], [0, 2, -2]]
  →  [-2, 0, 3, 5, 3]
 
length = 3, updates = []  →  [0, 0, 0]

Constraints

  • 1 <= length <= 10^5
  • 0 <= updates.length <= 10^4
  • 0 <= start <= end < length
  • -1000 <= inc <= 1000