Raise Stretches to Match
Start with a list of zeros that is as long as target. One move picks a stretch of positions next to each other (a single position counts too) and adds 1 to every item in it.
Return the fewest moves that turn the zeros into target.
Example 1
target [1,2,3,2,2]
returns 3
Raise all five positions, then the last four, then the middle one: 3 moves.
Example 2
target [3,1,5]
returns 7
The first item needs 3 moves that cover it. The last item is higher than its neighbor by 4, so 4 more moves must start there.
Constraints
0 <= len(target) <= 1000 <= target[i] <= 10**9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.