#K40842. Pair with Target Sum

    ID: 26732 Type: Default 1000ms 256MiB

Pair with Target Sum

Pair with Target Sum

Given an array of integers and an integer target (k), determine whether there exists a pair of distinct elements whose sum is exactly (k).

For instance, if the array is [10, 15, 3, 7] and (k = 17), the answer is True since (10 + 7 = 17).

This problem tests your ability to efficiently search for complementary pairs in an array. Use appropriate data structures to achieve an optimal solution.

inputFormat

The input is provided via standard input (stdin) and consists of three lines:
1. The first line contains an integer (n), the number of elements in the array.
2. The second line contains (n) space-separated integers representing the array elements (if (n = 0), this line will be empty).
3. The third line contains an integer (k), the target sum.

outputFormat

Output a single line to standard output (stdout): "True" if there exists a pair of distinct elements whose sum is (k), and "False" otherwise.## sample

4
10 15 3 7
17
True