#K39652. Two Sum Exists
Two Sum Exists
Two Sum Exists
You are given an array of n integers and an integer target. Your task is to determine whether there exist two distinct elements in the array whose sum is equal to the target value.
More formally, given an array \(a_1, a_2, \dots, a_n\) and a target value \(T\), check if there exist indices \(i\) and \(j\) with \(i \neq j\) such that:
\(a_i + a_j = T\)
If such a pair exists, output YES
, otherwise output NO
.
inputFormat
The input consists of three lines:
- The first line contains an integer
n
, representing the number of elements in the array. - The second line contains
n
space-separated integers, representing the array elements. - The third line contains an integer
target
, representing the sum to check.
outputFormat
Output a single line containing either YES
if there exists a pair of distinct elements whose sum is equal to target
, or NO
otherwise.
4
1 2 3 4
5
YES