#C13764. Two Sum to Target
Two Sum to Target
Two Sum to Target
Given a list of integers and a target integer \(T\), determine whether there exist two distinct integers in the list whose sum is exactly \(T\). In other words, check if there exist indices \(i\) and \(j\) (with \(i \neq j\)) such that \(a_i + a_j = T\).
The input is provided as follows:
- The first line contains a single integer \(N\) which is the number of integers in the list.
- The second line contains \(N\) space-separated integers.
- The third line contains a single integer representing the target \(T\).
The output should be True
if such a pair exists, and False
otherwise.
Note: The two integers used must come from different positions even if they have the same value.
inputFormat
The first line contains an integer \(N\) denoting the number of elements in the array.
The second line contains \(N\) space-separated integers representing the elements of the array.
The third line contains an integer \(T\), the target sum.
outputFormat
Output a single line: True
if there exist two different numbers in the list that add up to \(T\); otherwise, output False
.
5
1 2 3 4 5
8
True
</p>