Problem statement
You start with an array of zeroes. You are then given many range updates, each one saying: add a fixed amount to every value from position l to position r. After all updates, output the final array.
The intended solution applies each update in two quick marks and rebuilds the values in one pass at the end.
Examples
Inputstart [0, 0, 0, 0, 0]; updates: +5 on [1, 3], -2 on [2, 4]
Output[0, 5, 3, 3, -2]
Position 2 carries both updates: 5 - 2 = 3.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing