#K48152. Find Pair with Target Sum
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:
- An integer \(n\) representing the number of elements in the array.
- A line with \(n\) space separated integers.
- 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 []
.
4
2 7 11 15
9
[0, 1]