Minimum increment operations to make the array in increasing order | Function to find minimum moves required to make the array in increasing order ; To store answer ; Tterate over an array ; Non - increasing order ; Add moves to answer ; Increase the element ; Return required answer ; Driver code
function MinimumMoves ( a , n , x ) { var ans = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= a [ i - 1 ] ) { var p = parseInt ( ( a [ i - 1 ] - a [ i ] ) / x + 1 ) ; ans += p ; a [ i ] += p * x ; } } return ans ; } var arr = [ 1 , 3 , 3 , 2 ] ; var x = 2 ; var n = arr . length ; document . write ( MinimumMoves ( arr , n , x ) ) ;