#K47372. Two Sum Problem

    ID: 28184 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

You are given an array of integers and a target integer \(T\). Your task is to find two distinct indices \(i\) and \(j\) such that their corresponding numbers add up to the target, i.e.,

\(nums[i] + nums[j] = T\)

It is guaranteed that there is exactly one solution for each test case.


Note: The solution must work for multiple test cases. The input will first specify the number of test cases. For each test case, the first line contains two integers \(n\) (the length of the array) and \(T\) (the target sum). The next line contains \(n\) space-separated integers representing the array. For each test case, output the two indices (zero-indexed) separated by a space.

inputFormat

The first line of input contains an integer (t) representing the number of test cases.\nFor each test case:\n - The first line contains two integers: (n) (the number of elements in the array) and (T) (the target sum).\n - The second line contains (n) space-separated integers representing the array.

outputFormat

For each test case, output two space-separated integers representing the indices of the two numbers that add up to (T). Each answer should be on a new line.## sample

3
4 9
2 7 11 15
3 6
3 2 4
2 -1
-1 0
0 1

1 2 0 1

</p>