human
Minimum Increment / decrement to make array elements equal | Function to return minimum operations need to be make each element of array equal.
Initialize cost to 0.
Sort the array.
Middle element.
Find Cost.
If n , is even . Take minimum of the Cost obtained by considering both middle elements.
FInd cost again.
Take minimum of two cost.
Return total cost.
Driver code"
Solution in Python:
assistant
#Here is code to minimum Increment / decrement to make array elements equal and the other steps required.
 def minCost ( A , n ) :
	cost = 0
	A . sort ( ) ;
	K = A [ int ( n / 2 ) ]
	for i in range ( 0 , n ) :
		cost = cost + abs ( A [ i ] - K )
	if n % 2 == 0 :
		tempCost = 0
		K = A [ int ( n / 2 ) - 1 ]
		for i in range ( 0 , n ) :
			tempCost = tempCost + abs ( A [ i ] - K )
		cost = min ( cost , tempCost )
	return cost
A = [ 1 , 6 , 7 , 10 ]
n = len ( A )
print ( minCost ( A , n ) )