#C6371. Pair Sum Query in an Array
Pair Sum Query in an Array
Pair Sum Query in an Array
You are given an array of integers and a target integer. Your task is to determine whether there exist two distinct indices i and j (i ≠ j) such that:
If such a pair exists, output True
; otherwise, output False
. This is a typical two-sum problem often solved using hashing or two-pointer techniques.
Example:
- For
arr = [1, 2, 3, 4]
andtarget = 5
, one valid pair is (1,4), so the answer isTrue
.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains two integers
n
andtarget
, wheren
is the number of elements in the array. - The second line contains
n
space-separated integers representing the elements of the array.
For example:
4 5 1 2 3 4
outputFormat
Output a single line to standard output (stdout) containing either True
or False
(without quotes), depending on whether a pair exists that sums up to the target value.
4 5
1 2 3 4
True