human
Give me a code to maximum value of expression ( arr [ i ] + arr [ j ] * arr [ k ] ) formed from a valid Triplet and the other steps required given the following:
Maximum value of expression ( arr [ i ] + arr [ j ] * arr [ k ] ) formed from a valid Triplet | Function that generate all valid triplets and calculate the value of the valid triplets.
Generate all triplets.
Check whether the triplet is valid or not.
Update the value.
Print the maximum value.
Driver Code.
Given array arr.
Function call"
How can the above be solved in Python?
assistant
#Here is code to maximum value of expression ( arr [ i ] + arr [ j ] * arr [ k ] ) formed from a valid Triplet and the other steps required.
 def max_valid_triplet ( A , n ) :
	ans = - 1 ;
	for i in range ( 0 , n - 2 ) :
		for j in range ( i + 1 , n - 1 ) :
			for k in range ( j + 1 , n ) :
				if ( A [ i ] < A [ j ] and A [ j ] < A [ k ] ) :
					value = A [ i ] + A [ j ] * A [ k ] ;
					if ( value > ans ) :
						ans = value ;
	print ( ans ) ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 7 , 9 , 3 , 8 , 11 , 10 ] ;
	n = len ( arr ) ;
	max_valid_triplet ( arr , n ) ;