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 ; Prsecond largest product pair ; Driver Code ; Given array ; Function Call
def maxProduct ( arr , N ) : NEW_LINE INDENT if ( N < 3 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT arr . sort ( ) ; NEW_LINE smallest1 = arr [ 0 ] ; NEW_LINE smallest3 = arr [ 2 ] ; NEW_LINE largest1 = arr [ N - 1 ] ; NEW_LINE largest3 = arr [ N - 3 ] ; NEW_LINE if ( smallest1 * smallest3 >= largest1 * largest3 ) : NEW_LINE INDENT print ( smallest1 , " ▁ " , smallest3 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( largest1 , " ▁ " , largest3 ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 5 , 2 , 67 , 45 , 160 , 78 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE maxProduct ( arr , N ) ; NEW_LINE DEDENT