human
Write me a code to minimum number of subtract operation to make an array decreasing and the other steps required given the following:
Minimum number of subtract operation to make an array decreasing | Function to count minimum no of operation.
Count how many times we have to subtract ..
Check an additional subtraction is required or not ..
Modify the value of arr [ i ] ..
Count total no of operation / subtraction ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimum number of subtract operation to make an array decreasing and the other steps required.
 def min_noOf_operation ( arr , n , k ) :
	res = 0
	for i in range ( 1 , n ) :
		noOfSubtraction = 0
		if ( arr [ i ] > arr [ i - 1 ] ) :
			noOfSubtraction = ( arr [ i ] - arr [ i - 1 ] ) / k ;
			if ( ( arr [ i ] - arr [ i - 1 ] ) % k != 0 ) :
				noOfSubtraction += 1
			arr [ i ] = arr [ i ] - k * noOfSubtraction
		res = res + noOfSubtraction
	return int ( res )
arr = [ 1 , 1 , 2 , 3 ]
N = len ( arr )
k = 5
print ( min_noOf_operation ( arr , N , k ) )