values. In one step you may increase or decrease any element by 1.
Return the minimum number of steps after which all elements are equal.values=[4, 1, 7] → 6
Bring everything to 4: raise 1 by 3 and lower 7 by 3, 6 steps in total.
values=[0, 10, 2, 9] → 17
Any target from 2 to 9 costs the same; for 5 it is 5 + 5 + 3 + 4 = 17.
values=[-3, -3] → 0
values=[4, 1, 7]
6
Run checks the first 3 tests in your browser. Submit checks all 76 tests on the server, hidden ones included.