Here, incrementing all numbers except one is equivalent to decrementing that one number, as we only care about the fact that the numbers are equal. Thus, the solution is equivalent to decrementing every number to the minimum in the array. The amount of operations done to the each element would result in the general formula sum - length*minimum.
Array problems as such are good build-ups for this larger problem: #212
Problem: https://leetcode.com/problems/minimum-moves-to-equal-array-elements/
Here, incrementing all numbers except one is equivalent to decrementing that one number, as we only care about the fact that the numbers are equal. Thus, the solution is equivalent to decrementing every number to the minimum in the array. The amount of operations done to the each element would result in the general formula
sum - length*minimum
.Array problems as such are good build-ups for this larger problem: #212