human
Print all triplets in sorted array that form AP | Function to print all triplets in given sorted array that forms AP.
Search other two elements of AP with arr [ i ] as middle ..
if a triplet is found.
Since elements are distinct , arr [ k ] and arr [ j ] cannot form any more triplets with arr [ i ].
If middle element is more move to higher side , else move lower side ..
Driver code"
Solution in Python:
assistant
#Here is code to print all triplets in sorted array that form AP and the other steps required.
 def printAllAPTriplets ( arr , n ) :
	for i in range ( 1 , n - 1 ) :
		j = i - 1
		k = i + 1
		while ( j >= 0 and k < n ) :
			if ( arr [ j ] + arr [ k ] == 2 * arr [ i ] ) :
				print ( arr [ j ] , " " , arr [ i ] , " " , arr [ k ] )
				k += 1
				j -= 1
			elif ( arr [ j ] + arr [ k ] < 2 * arr [ i ] ) :
				k += 1
			else :
				j -= 1
arr = [ 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 ]
n = len ( arr )
printAllAPTriplets ( arr , n )