Consider an array a=[1, 1, 2, 2, 3, 3].Two operations are required to make the array equal that is decrement both the three’s by 1 and add it to both the one’s.
Do we pick a pair of different indexes for each operation to increment one value and decrement the other? If yes, then the key observation is that each operation does not change the total sum of all elements in the array (let’s say the total sum is S and it remains the same). If solution exists and we are able to make all elements equal, then S has to be divisible by the size of the array N and each element becomes equal to X = S / N. Then the number of individual increments and decrements can be obtained by iterating over all elements of the array \sum\limits_{i=1}^N \vert {A_i-X} \vert. To get your answer (the number of increment/decrement pairs), just divide this sum by 2. And again, making the array equal is impossible if S is not divisible by N, one of the examples of a bad array is a=[2, 3]
Or do we pick the type of operation (increment or decrement) and multiple array indexes to update them all as a single operation? If yes, then the key observation is that a single operation can either decrease the maximum value of the array by 1 or increase the minimum value of the array by 1. The answer is just the difference between the maximum and the minimum array values. There’s no way to reduce the number of operations further.