human
Maximum triplet sum in array | This function assumes that there are at least three elements in arr [ ] ..
Initialize Maximum , second maximum and third maximum element.
Update Maximum , second maximum and third maximum element.
Update second maximum and third maximum element.
Update third maximum element.
Driven code"
How can the above be solved in Python?
 Write me a code to maximum triplet sum in array and the other steps required?
assistant
#Here is code to maximum triplet sum in array and the other steps required.
 def maxTripletSum ( arr , n ) :
	maxA = - 100000000
	maxB = - 100000000
	maxC = - 100000000
	for i in range ( 0 , n ) :
		if ( arr [ i ] > maxA ) :
			maxC = maxB
			maxB = maxA
			maxA = arr [ i ]
		elif ( arr [ i ] > maxB ) :
			maxC = maxB
			maxB = arr [ i ]
		elif ( arr [ i ] > maxC ) :
			maxC = arr [ i ]
	return ( maxA + maxB + maxC )
arr = [ 1 , 0 , 8 , 6 , 4 , 2 ]
n = len ( arr )
print ( maxTripletSum ( arr , n ) )