human
All unique triplets that sum up to a given value | Function to all find unique triplets without using extra space.
Sort the input array.
For handling the cases when no such triplets exits ..
Iterate over the array from start to n - 2..
Index of the first element in remaining range ..
Index of the last element.
Setting our new target.
Checking if current element is same as previous.
Checking if current element is same as previous.
If we found the triplets then print it and set the flag.
If target is greater then increment the start index.
If target is smaller than decrement the end index.
If no such triplets found.
Driver code.
Function call"
Solution in Python:
 Can you provide a code to all unique triplets that sum up to a given value and the other steps required?
assistant
#Here is code to all unique triplets that sum up to a given value and the other steps required.
 def findTriplets ( a , n , sum ) :
	a . sort ( )
	flag = False
	for i in range ( n - 2 ) :
		if ( i == 0 or a [ i ] > a [ i - 1 ] ) :
			start = i + 1
			end = n - 1
			target = sum - a [ i ]
			while ( start < end ) :
				if ( start > i + 1 and a [ start ] == a [ start - 1 ] ) :
					start += 1
					continue
				if ( end < n - 1 and a [ end ] == a [ end + 1 ] ) :
					end -= 1
					continue
				if ( target == a [ start ] + a [ end ] ) :
					print ( " [ " , a [ i ] , " , " , a [ start ] , " , " , a [ end ] , " ] " , end = " ▁ " )
					flag = True
					start += 1
					end -= 1
				elif ( target > ( a [ start ] + a [ end ] ) ) :
					start += 1
				else :
					end -= 1
	if ( flag == False ) :
		print ( " No ▁ Such ▁ Triplets ▁ Exist " )
if __name__ == " _ _ main _ _ " :
	a = [ 12 , 3 , 6 , 1 , 6 , 9 ]
	n = len ( a )
	sum = 24
	findTriplets ( a , n , sum )