Find a pair in Array with second largest product | Function to find second largest product pair in arr [ 0. . n - 1 ] ; No pair exits ; Sort the array ; Initialize smallest element of the array ; Initialize largest element of the array ; Prlet second largest product pair ; Given array ; Function Call
function maxProduct ( arr , N ) { if ( N < 3 ) { return ; } arr . sort ( ( a , b ) => a - b ) let smallest1 = arr [ 0 ] ; let smallest3 = arr [ 2 ] ; let largest1 = arr [ N - 1 ] ; let largest3 = arr [ N - 3 ] ; if ( smallest1 * smallest3 >= largest1 * largest3 ) { document . write ( smallest1 + " " + smallest3 ) ; } else { document . write ( largest1 + " " + largest3 ) ; } } let arr = [ 5 , 2 , 67 , 45 , 160 , 78 ] ; let N = arr . length ; maxProduct ( arr , N ) ;