#K94602. Two Sum Problem: Find a Pair that Sums to a Target
Two Sum Problem: Find a Pair that Sums to a Target
Two Sum Problem: Find a Pair that Sums to a Target
You are given an array of integers A
of size n and a target integer T
. Your task is to find a pair of numbers a and b from the array such that:
$$a+b=T$$
Each input should have at most one valid pair and the same element cannot be used twice. If such a pair does not exist, output an empty line.
Note: The input is read from standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The input begins with an integer n
representing the number of elements in the array. The next line contains n
space-separated integers. The last line contains the target integer T
.
Example:
4 2 7 11 15 9
outputFormat
If a pair is found, output the two integers separated by a space (in the order they are discovered). If no such pair exists, output an empty line.
Example:
2 7## sample
4
2 7 11 15
9
2 7