levels. You need to set them to the preset preset of the same length: slider i must end up at level preset[i].
In one move you may take any block of **consecutive** sliders and shift all of them by 1 together, either all up or all down.
Return the smallest number of moves after which levels matches preset.levels=[2, 2, 5, 5], preset=[3, 4, 6, 5] → 2
Raise sliders 0–2 by one: [3, 3, 6, 5]. Then raise slider 1 once more: [3, 4, 6, 5]. Two moves in total.
levels=[4, 4, 4], preset=[5, 3, 5] → 3
Sliders 0 and 2 must go up while slider 1 between them must go down, so no single block covers them: one move each, 3 in total.
levels=[7, 7], preset=[7, 7] → 0
Everything already matches, so no moves are needed.
levels.length = preset.length ≤ 10⁵levels[i], preset[i] ≤ 10⁸levels=[2, 2, 5, 5], preset=[3, 4, 6, 5]
2
Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.