Find a pair ( n , r ) in an integer array such that value of nPr is maximum | Function to print the pair ( n , r ) such that nPr is maximum possible ; There should be atleast 2 elements ; Findex the largest 2 elements ; Driver code
function findPair ( arr , n ) { if ( n < 2 ) { document . write ( " " ) ; return ; } let i , first , second ; first = second = - 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second ) { second = arr [ i ] ; } } document . write ( " " + first + " " + second ) ; } let arr = [ 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 ] ; let n = arr . length ; findPair ( arr , n ) ;