#K69587. Two Sum Existence
Two Sum Existence
Two Sum Existence
You are given a list of integers and a target integer. Your task is to determine whether there exist two distinct indices (i) and (j) such that
[
nums[i] + nums[j] = target
]
If such a pair exists, print YES
; otherwise, print NO
.
For example, if the input is:
5 9 2 7 11 15 1
Since (2 + 7 = 9), the answer is YES
.
Note: The two integers must come from two different positions in the list.
inputFormat
The first line contains two integers, (n) and (target), where (n) is the number of elements in the array and (target) is the desired sum. The second line contains (n) space-separated integers representing the array (nums).
outputFormat
Output a single line with either YES
if there exist two distinct indices (i) and (j) such that (nums[i] + nums[j] = target), or NO
otherwise.## sample
5 9
2 7 11 15 1
YES