text: Minimum steps for increasing and decreasing Array to reach either 0 or N | Function that finds the minimum steps to reach either 0 or N for given increasing and decreasing arrays ; Initialize variable to find the minimum element ; Find minimum element in increasing [ ] array ; Initialize variable to find the maximum element ; Find maximum element in decreasing [ ] array ; Find the minimum steps ; Print the minimum steps ; Given N ; Given increasing and decreasing array ; Find length of arrays increasing and decreasing ; Function call
code: function minSteps ( N , increasing , decreasing , m1 , m2 ) { var mini = 2147483647 ; var i ; for ( i = 0 ; i < m1 ; i ++ ) { if ( mini > increasing [ i ] ) mini = increasing [ i ] ; } var maxi = - 2147483648 ; for ( i = 0 ; i < m2 ; i ++ ) { if ( maxi < decreasing [ i ] ) maxi = decreasing [ i ] ; } var minSteps = Math . max ( maxi , N - mini ) ; document . write ( minSteps ) ; } var N = 7 ; var increasing = [ 3 , 5 ] ; var decreasing = [ 6 ] ; var m1 = increasing . length ; var m2 = decreasing . length ; minSteps ( N , increasing , decreasing , m1 , m2 ) ;