heights, and every post must be moved either exactly shift up or exactly shift down; leaving a post where it is is not allowed (unless shift is zero).
The spread of the row is the difference between its tallest and shortest post. Return the smallest spread you can get after moving every post.heights=[2, 9, 5], shift=3 → 3
Raise 2 and 5, lower 9: that gives 5, 6 and 8. The spread is 8 - 5 = 3, and nothing does better.
heights=[4], shift=7 → 0
With a single post the spread is always 0.
heights=[1, 10], shift=2 → 5
heights=[2, 9, 5], shift=3
3
Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.