#K13166. Two Sum Existence
Two Sum Existence
Two Sum Existence
You are given an array of integers and an integer target k. Your task is to determine whether there exist two different indices i and j in the array such that the following equation holds:
\(arr[i] + arr[j] = k\)
If such a pair exists, print YES; otherwise, print NO. The answer for each test case should be output on a separate line in the format Case i: YES
or Case i: NO
, where i
is the test case number (starting from 1).
This problem tests your ability to efficiently search for pairs in arrays using techniques such as hashing.
inputFormat
The input begins with an integer T
on the first line, representing the number of test cases.
Each test case is described as follows:
- The first line of each test case contains two integers
n
andk
, wheren
is the number of elements in the array, andk
is the target sum. - The second line contains
n
space-separated integers representing the array elements.
outputFormat
For each test case, output a single line in the following format:
Case i: YES
or Case i: NO
Here, i
is the test case number (starting from 1), and the answer is YES
if there exist two distinct indices such that arr[i] + arr[j] = k
(where i ≠ j
), and NO
otherwise.
3
4 9
2 7 11 15
3 10
1 5 3
5 7
1 2 3 4 5
Case 1: YES
Case 2: NO
Case 3: YES
</p>