human
Minimum increments or decrements by D required to make all array elements equal | Function to find minimum count of operations required to make all array elements equal by incrementing or decrementing array elements by d.
Sort the array.
Traverse the array.
If difference between two consecutive elements are not divisible by D.
Store minimum count of operations required to make all array elements equal by incrementing or decrementing array elements by d.
Stores middle element of the array.
Traverse the array.
Update count.
Driver Code.
Given N & D.
Given array arr [ ].
Function Call"
How can the above be solved in Python?
 Can you provide a code to minimum increments or decrements by D required to make all array elements equal and the other steps required?
assistant
#Here is code to minimum increments or decrements by D required to make all array elements equal and the other steps required.
 def numOperation ( arr , N , D ) :
	arr . sort ( )
	for i in range ( N - 1 ) :
		if ( ( arr [ i + 1 ] - arr [ i ] ) % D != 0 ) :
			print ( " - 1" )
			return
	count = 0
	mid = arr [ N // 2 ]
	for i in range ( N ) :
		count += abs ( mid - arr [ i ] ) // D
	print ( count )
if __name__ == " _ _ main _ _ " :
	N = 4
	D = 2
	arr = [ 2 , 4 , 6 , 8 ]
	numOperation ( arr , N , D )