Find a pair from the given array with maximum nCr value | Function to print the pair that gives maximum nCr ; This gives the value of N in nCr ; Case 1 : When N is odd ; Case 2 : When N is even ; Driver code
function printMaxValPair ( v , n ) { v . sort ( ( a , b ) => a - b ) var N = v [ n - 1 ] ; if ( N % 2 == 1 ) { var first_maxima = N / 2 ; var second_maxima = first_maxima + 1 ; var ans1 = 3000000000000000000 , ans2 = 3000000000000000000 ; var from_left = - 1 , from_right = - 1 ; var from = - 1 ; for ( var i = 0 ; i < n ; ++ i ) { if ( v [ i ] > first_maxima ) { from = i ; break ; } else { var diff = first_maxima - v [ i ] ; if ( diff < ans1 ) { ans1 = diff ; from_left = v [ i ] ; } } } from_right = v [ from ] ; var diff1 = first_maxima - from_left ; var diff2 = from_right - second_maxima ; if ( diff1 < diff2 ) document . write ( N + " " + from_left ) ; else document . write ( N + " " + from_right ) ; } else { var maxima = parseInt ( N / 2 ) ; var ans1 = 3000000000000000000 ; var R = - 1 ; for ( var i = 0 ; i < n - 1 ; ++ i ) { var diff = Math . abs ( v [ i ] - maxima ) ; if ( diff < ans1 ) { ans1 = diff ; R = v [ i ] ; } } document . write ( N + " " + R ) ; } } var v = [ 1 , 1 , 2 , 3 , 6 , 1 ] ; var n = v . length ; printMaxValPair ( v , n ) ;