#K88177. Two Sum Problem

    ID: 37251 Type: Default 1000ms 256MiB

Two Sum Problem

Two Sum Problem

Given an array of integers and a target integer \(T\), your task is to find two distinct indices \(i\) and \(j\) such that \(a_i + a_j = T\). The indices are zero-based. If there is a valid pair, output the two indices separated by a space. Otherwise, output [] to indicate that no such pair exists.

For example, if the array is [2, 7, 11, 15] and \(T=9\), one valid solution is to return the indices 0 and 1 because \(2+7=9\).

Note: If multiple pairs are possible, output the first valid pair found using a left-to-right scan.

inputFormat

The input is given in three lines:

  • The first line contains an integer \(n\), representing the number of elements in the array.
  • The second line contains \(n\) space-separated integers.
  • The third line contains an integer \(T\), the target sum.

outputFormat

If there exists a pair of indices \(i\) and \(j\) such that \(a_i + a_j = T\), output them in one line separated by a single space. If no such pair exists, output [].

## sample
4
2 7 11 15
9
0 1