Two Pointers Technique | Naive solution to find if there is a pair in A [ 0. . N - 1 ] with given sum . ; as equal i and j means same element ; pair exists ; as the array is sorted ; No pair found with given sum ; Driver code ; Function call
def isPairSum ( A , N , X ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( A [ i ] + A [ j ] == X ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( A [ i ] + A [ j ] > X ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT return 0 NEW_LINE DEDENT arr = [ 3 , 5 , 9 , 2 , 8 , 10 , 11 ] NEW_LINE val = 17 NEW_LINE print ( isPairSum ( arr , len ( arr ) , val ) ) NEW_LINE