#C7750. Pair with Sum in a Sorted Array
Pair with Sum in a Sorted Array
Pair with Sum in a Sorted Array
You are given a sorted array of integers and a target integer \(T\). Your task is to determine whether there exists a pair of distinct numbers in the array whose sum is exactly \(T\).
Formally, given a sorted array \(A\) of size \(n\) and an integer \(T\), determine if there exist indices \(i\) and \(j\) with \(i < j\) such that:
[ A[i] + A[j] = T ]
If such a pair exists, print True
; otherwise, print False
.
Note: An efficient two-pointer approach with \(O(n)\) time complexity is expected.
inputFormat
The input is read from standard input and consists of:
- An integer \(n\) representing the number of elements in the array.
- A line with \(n\) space-separated sorted integers.
- An integer representing the target sum \(T\).
For example:
7 -10 -3 0 2 5 9 11 7
outputFormat
Print a single line to standard output: True
if a valid pair exists, or False
otherwise.
7
-10 -3 0 2 5 9 11
7
True