Maximum product quadruple ( sub | Python3 program to find a maximum product of a quadruple in array of integers ; Function to find a maximum product of a quadruple in array of integers of size n ; if size is less than 4 , no quadruple exists ; will contain max product ; Driver Code
import sys NEW_LINE def maxProduct ( arr , n ) : NEW_LINE INDENT if ( n < 4 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT max_product = - sys . maxsize ; NEW_LINE for i in range ( n - 3 ) : NEW_LINE INDENT for j in range ( i + 1 , n - 2 ) : NEW_LINE INDENT for k in range ( j + 1 , n - 1 ) : NEW_LINE INDENT for l in range ( k + 1 , n ) : NEW_LINE INDENT max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] * arr [ l ] ) ; NEW_LINE DEDENT DEDENT DEDENT DEDENT return max_product ; NEW_LINE DEDENT arr = [ 10 , 3 , 5 , 6 , 20 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE max = maxProduct ( arr , n ) ; NEW_LINE if ( max == - 1 ) : NEW_LINE INDENT print ( " No ▁ Quadruple ▁ Exists " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Maximum ▁ product ▁ is " , max ) ; NEW_LINE DEDENT