Minimum increments of Non | Function to return to the minimum number of operations required to make the array non - decreasing ; Stores the count of operations ; If arr [ i ] > arr [ i + 1 ] , add arr [ i ] - arr [ i + 1 ] to the answer Otherwise , add 0 ; Driver Code
def getMinOps ( arr ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( len ( arr ) - 1 ) : NEW_LINE INDENT ans += max ( arr [ i ] - arr [ i + 1 ] , 0 ) NEW_LINE DEDENT return ans NEW_LINE DEDENT arr = [ 1 , 3 , 1 , 2 , 4 ] NEW_LINE print ( getMinOps ( arr ) ) NEW_LINE