Two Sum in Sorted Array
Easyjavapythonccppjavascript
Given a sorted array and a target value, determine whether two elements at different positions add up to the target, using the two-pointer technique.
Input Format
The first line contains two integers N and target. The second line contains N space-separated integers in non-decreasing order.
Output Format
Print 1 if such a pair exists, otherwise print 0.
Example 1
Input
7 13 1 2 4 6 8 9 14
Output
1
Explanation: 4 + 9 = 13.
- 2 <= N <= 100000
- The array is sorted in non-decreasing order.
- -1000000000 <= A[i], target <= 1000000000