#K41032. Two Sum Indices
Two Sum Indices
Two Sum Indices
Given a list of integers and a target integer T, find indices i and j (with i < j
) such that:
\( nums[i] + nums[j] = T \)
You are guaranteed that there is exactly one solution for each test case.
This is a classic problem that can be efficiently solved using a hash table. In this problem, multiple test cases are provided in a single input.
inputFormat
The first line contains an integer T, the number of test cases. For each test case:
- The first line contains two integers:
target
andn
(the number of elements in the array). - The next line contains
n
space-separated integers representing the list.
All input is read from standard input (stdin).
outputFormat
For each test case, output a single line containing two space-separated integers, which are the indices of the two numbers that add up to the target. The output is written to standard output (stdout).
## sample4
9 5
2 7 11 15 5
6 4
3 2 4 8
10 5
1 2 3 4 6
17 4
2 7 11 15
0 1
1 2
3 4
0 3
</p>