#K58992. Two Sum Indices

    ID: 30765 Type: Default 1000ms 256MiB

Two Sum Indices

Two Sum Indices

You are given an array of integers and a target integer \(T\). Your task is to find two distinct indices \(i\) and \(j\) in the array such that:

[ \text{arr}[i] + \text{arr}[j] = T ]

You can assume that each input has exactly one solution and you may not use the same element twice. This is a classic problem that can be solved efficiently using a hash table (dictionary).

The input consists of several test cases. The first line of the input contains the number of test cases \(Q\). Each test case is described as follows:

  • An integer \(n\) representing the number of elements.
  • A line with \(n\) space-separated integers representing the array.
  • An integer \(T\) representing the target sum.

For each test case, output two integers representing the indices of the two numbers that add up to \(T\). The indices should be printed in one line, separated by a space.

inputFormat

The first line contains a single integer \(Q\) denoting the number of test cases. For each test case, the input is given in the following order:

  • An integer \(n\) (the size of the array).
  • A line containing \(n\) integers separated by a space, representing the array elements.
  • An integer \(T\) representing the target sum.

All input is read from standard input (stdin).

outputFormat

For each test case, output a single line with two integers separated by a space: the indices of the two numbers that add up to the target \(T\). Output is written to standard output (stdout).

## sample
2
4
2 7 11 15
9
3
3 2 4
6
0 1

1 2

</p>