human
Two Pointers Technique | Two pointer technique based solution to find if there is a pair in A [ 0. . N - 1 ] with a given sum ..
represents first pointer.
represents second pointer.
If we find a pair.
If sum of elements at current pointers is less , we move towards higher values by doing i += 1.
If sum of elements at current pointers is more , we move towards lower values by doing j -= 1.
array declaration.
value to search.
Function call"
How can the above be solved in Python?
assistant
#Here is code to two Pointers Technique and the other steps required.
 def isPairSum ( A , N , X ) :
	i = 0
	j = N - 1
	while ( i < j ) :
		if ( A [ i ] + A [ j ] == X ) :
			return True
		elif ( A [ i ] + A [ j ] < X ) :
			i += 1
		else :
			j -= 1
	return 0
arr = [ 3 , 5 , 9 , 2 , 8 , 10 , 11 ]
val = 17
print ( isPairSum ( arr , len ( arr ) , val ) )