Minimum number of operations required to make an array non | C # program for the above approach ; 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
using System ; using System . Collections . Generic ; class GFG { static int countMinSteps ( int [ ] arr , int N ) { int val = 0 ; int mx = Int32 . MinValue ; for ( int i = 0 ; i < N ; i ++ ) { int curr = arr [ i ] ; mx = Math . Max ( mx , curr ) ; val = Math . Max ( val , mx - curr ) ; } int res = 0 ; while ( ( 1 << res ) - 1 < val ) { ++ res ; } return res ; } public static void Main ( ) { int [ ] arr = { 1 , 7 , 6 , 5 } ; int N = arr . Length ; Console . Write ( countMinSteps ( arr , N ) ) ; } }