#K48152. Find Pair with Target Sum

    ID: 28357 Type: Default 1000ms 256MiB

Find Pair with Target Sum

Find Pair with Target Sum

Given an array of integers and a target sum \(T\), find two distinct indices \(i\) and \(j\) in the array such that the sum of the elements at these indices equals \(T\). If such a pair exists, output the indices in ascending order enclosed in square brackets, e.g. [i, j]. If no such pair exists, output an empty list: [].

The input consists of three lines:

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

Note: Each test is executed independently using standard input and standard output.

inputFormat

The input from standard input (stdin) is formatted as follows:

  1. An integer \(n\) representing the number of elements in the array.
  2. A line with \(n\) space separated integers.
  3. An integer representing the target sum \(T\).

outputFormat

Output to standard output (stdout) a single line containing the result. If a pair exists, output the two indices in ascending order in the format [i, j]. If no such pair exists, output [].

## sample
4
2 7 11 15
9
[0, 1]