levels[i] is the brightness of lamp i. The street counts as lit when **every three consecutive lamps** include at least one whose brightness is at least need.
In one step you can pick any lamp and raise its brightness by 1. Brightness can never be lowered.
Return the smallest number of steps that makes the street lit.
Note that once every run of three consecutive lamps is fine, every longer run is fine too.levels=[1, 4, 0, 2, 0, 1], need=3 → 1
The triples [1, 4, 0] and [4, 0, 2] are already covered by the lamp at 4. The triples [0, 2, 0] and [2, 0, 1] both contain the lamp at index 3, so raising it from 2 to 3 costs one step.
levels=[0, 0, 0, 0, 0, 0, 0], need=2 → 4
Making the lamps at indices 2 and 5 bright is enough, since every run of three touches one of them. That is 2 + 2 = 4 steps.
levels=[7, 1, 1], need=5 → 0
The only triple already holds a lamp at 7, so nothing needs to change.
levels=[1, 4, 0, 2, 0, 1], need=3
1
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.