#K43457. Pair with Given Sum
Pair with Given Sum
Pair with Given Sum
Given a list of unique integers and a target integer \(T\), determine whether there exists any pair of integers in the list whose sum is equal to \(T\). In other words, you need to check if there exist two distinct indices\(i\) and \(j\) such that:
\(a_i + a_j = T\)
The input is provided via standard input (stdin) and the output should be printed to standard output (stdout) as either True
or False
. The challenge is to design an algorithm that runs in \(O(n)\) average time complexity.
Example:
Input: 4 1 2 4 4 8</p>Output: True
inputFormat
The first line contains a single integer \(n\) which represents the number of elements in the list.
The second line contains \(n\) space-separated integers, representing the elements of the list.
The third line contains an integer \(T\) denoting the target sum.
outputFormat
Output a single line: True
if there exists a pair of integers in the list that sum up to \(T\), otherwise output False
.
4
1 2 3 9
8
False
</p>