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 ; iterate over an array ; non - increasing order ; add moves to answer ; increase the element ; return required answer ; Driver code
< ? php function MinimumMoves ( & $ a , $ n , $ x ) { $ ans = 0 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { if ( $ a [ $ i ] <= $ a [ $ i - 1 ] ) { $ p = ( $ a [ $ i - 1 ] - $ a [ $ i ] ) / $ x + 1 ; $ ans += $ p ; $ a [ $ i ] += $ p * $ x ; } } return $ ans ; } $ arr = array ( 1 , 3 , 3 , 2 ) ; $ x = 2 ; $ n = sizeof ( $ arr ) ; echo ( ( int ) MinimumMoves ( $ arr , $ n , $ x ) ) ; ? >