#K83627. Two Sum Problem
Two Sum Problem
Two Sum Problem
You are given an array of integers \(A = [a_0, a_1, ..., a_{n-1}]\) and a target integer \(T\). Your task is to find two distinct indices \(i\) and \(j\) such that:
\(a_i + a_j = T\)
If such a pair exists, output the two indices separated by a space. Otherwise, output an empty list []
. Note that the indices are 0-indexed.
Example:
- Input: 4
2 7 11 15
9 - Output: 0 1
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains a single integer (n), the number of elements in the array.
- The second line contains (n) space-separated integers representing the array (A).
- The third line contains a single integer (T), the target sum.
outputFormat
The output should be printed to standard output (stdout). If a pair exists such that their sum is equal to (T), print the two indices separated by a space. If no such pair exists, print the string []
.## sample
4
2 7 11 15
9
0 1