Minimum number of operations required to make an array non | Function to count the minimum number of steps required to make arr non - decreasing ; Stores differences ; Stores the max number ; Traverse the array arr [ ] ; Update mx ; Update val ; Stores the result ; Iterate until 2 ^ res - 1 is less than val ; Return the answer ; Driver Code ; Given input ; Function call
def countMinSteps ( arr , N ) : NEW_LINE INDENT val = 0 NEW_LINE mx = - 10 ** 9 NEW_LINE for i in range ( N ) : NEW_LINE INDENT curr = arr [ i ] NEW_LINE mx = max ( mx , curr ) NEW_LINE val = max ( val , mx - curr ) NEW_LINE DEDENT res = 0 NEW_LINE while ( ( 1 << res ) - 1 < val ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 7 , 6 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE print ( countMinSteps ( arr , N ) ) NEW_LINE DEDENT