human
Making elements of two arrays same with minimum increment / decrement | Python 3 program to find minimum increment / decrement operations to make array elements same ..
sorting both arrays in ascending order.
variable to store the final result.
After sorting both arrays . Now each array is in non - decreasing order . Thus , we will now compare each element of the array and do the increment or decrement operation depending upon the value of array b [ ] ..
Driver code"
Solution in Python:
assistant
#Here is code to making elements of two arrays same with minimum increment / decrement and the other steps required.
 def MinOperation ( a , b , n ) :
	a . sort ( reverse = False )
	b . sort ( reverse = False )
	result = 0
	for i in range ( 0 , n , 1 ) :
		if ( a [ i ] > b [ i ] ) :
			result = result + abs ( a [ i ] - b [ i ] )
		elif ( a [ i ] < b [ i ] ) :
			result = result + abs ( a [ i ] - b [ i ] )
	return result
if __name__ == ' _ _ main _ _ ' :
	a = [ 3 , 1 , 1 ]
	b = [ 1 , 2 , 2 ]
	n = len ( a )
	print ( MinOperation ( a , b , n ) )