Data Structures19 sections · 729 units
Open in Course

The Range Update Problem

A different challenge

New problem: you have an array, and you need to add a value vv to all elements from index ll to rr. You'll do this many times, then read the final array.

Naive approach: loop from ll to rr, add vv to each element. Each update takes O(n)O(n) time. Can you do better? Yes. Difference arrays let you perform range updates in O(1)O(1).