Difference Array
Apply range updates in O(1), then prefix-sum to get result. LC 370, 1109, 1094.
Original
Diff array
Result
Updated range
Controls
Range update: O(1) | Build result: O(n)
Operations
0 stepsPress Run Demo to trace the algorithm one step at a time.