Find a pair in Array with second largest product | Function to find second largest product pair in arr [ 0. . n - 1 ] ; No pair exits ; Initialize max product pair ; Traverse through every possible pair and keep track of largest product ; If pair is largest ; Second largest ; If pair dose not largest but larger then second largest ; Print the pairs ; Driver Code ; Given array ; Function call
def maxProduct ( arr , N ) : NEW_LINE INDENT if ( N < 3 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT a = arr [ 0 ] ; b = arr [ 1 ] ; NEW_LINE c = 0 ; d = 0 ; NEW_LINE for i in range ( 0 , N , 1 ) : NEW_LINE INDENT for j in range ( i + 1 , N - 1 , 1 ) : NEW_LINE INDENT if ( arr [ i ] * arr [ j ] > a * b ) : NEW_LINE INDENT c = a ; NEW_LINE d = b ; NEW_LINE a = arr [ i ] ; NEW_LINE b = arr [ j ] ; NEW_LINE DEDENT if ( arr [ i ] * arr [ j ] < a * b and arr [ i ] * arr [ j ] > c * d ) : NEW_LINE INDENT c = arr [ i ] ; NEW_LINE DEDENT d = arr [ j ] ; NEW_LINE DEDENT DEDENT print ( c , " ▁ " , d ) ; NEW_LINE 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