values. In one operation you choose any leading part of the array (its first few elements, at least one) and add the same integer k to each of them; k may be negative.
Return the fewest operations needed to make all elements of the array equal.values=[5, 2, 2, 8] → 2
Add 6 to the first three: [11, 8, 8, 8]. Then add −3 to the first one: [8, 8, 8, 8]. Two operations.
values=[-4, -4] → 0
Everything is already equal, so no operations are needed.
values=[1, 3, 1, 3] → 3
values=[5, 2, 2, 8]
2
Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.