human
Minimize subtraction followed by increments of adjacent elements required to make all array elements equal | Function to find the minimum number of moves required to make all array elements equal.
Store the total sum of the array.
Calculate total sum of the array.
If the sum is not divisible by N , then print " - 1".
Stores the average.
Stores the count of operations.
Traverse the array arr [ ].
Update number of moves required to make current element equal to avg.
Update the overall count.
Return the minimum operations required.
Driver Code"
Solution in Python:
assistant
#Here is code to minimize subtraction followed by increments of adjacent elements required to make all array elements equal and the other steps required.
 def findMinMoves ( arr , N ) :
	sum = 0
	for i in range ( N ) :
		sum += arr [ i ]
	if ( sum % N != 0 ) :
		return - 1
	avg = sum // N
	total = 0
	needCount = 0
	for i in range ( N ) :
		needCount += ( arr [ i ] - avg )
		total = max ( max ( abs ( needCount ) , arr [ i ] - avg ) , total )
	return total
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 0 , 5 ]
	N = len ( arr )
	print ( findMinMoves ( arr , N ) )