#K33357. Two Sum Exists
Two Sum Exists
Two Sum Exists
You are given an array of integers and an integer target. Your task is to determine whether there exist two distinct indices i and j in the array such that the equation \(nums[i] + nums[j] = target\) holds.
The input format is as follows:
- 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 representing the target value.
Your program should output a single line: true
if such a pair exists, and false
otherwise.
inputFormat
The input is read from standard input (stdin) and has the following format:
n nums[0] nums[1] ... nums[n-1] target
Where:
- \(n\) is the number of elements in the array.
- \(nums[i]\) are the integer elements of the array.
target
is the integer target value.
outputFormat
The output is a single line to standard output (stdout) which is either:
true
if there exists a pair of distinct indices such that \(nums[i] + nums[j] = target\),- or
false
otherwise.
4
2 7 11 15
9
true
</p>