Minimum number of days required to complete the work | Function to find the minimum number days required ; initialising ans to least value possible ; sort by first i . e D ( i ) ; Calculate the minimum possible days ; return the answer ; Number of works ; D1 [ i ] ; D2 [ i ]
function minimumDays ( N , D1 , D2 ) { var ans = - 1000000000 ; var vect = [ ] ; for ( var i = 0 ; i < N ; i ++ ) vect . push ( [ D1 [ i ] , D2 [ i ] ] ) ; vect . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < N ; i ++ ) { if ( vect [ i ] [ 1 ] >= ans ) ans = vect [ i ] [ 1 ] ; else ans = vect [ i ] [ 0 ] ; } return ans ; } var N = 3 ; var D1 = [ 6 , 5 , 4 ] ; var D2 = [ 1 , 2 , 3 ] ; document . write ( minimumDays ( N , D1 , D2 ) ) ;