#K14966. Two Sum Indices
Two Sum Indices
Two Sum Indices
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 the sum \(a[i] + a[j] = T\). If no such pair exists, output -1 -1
. The indices are 0-based.
Note: If there are multiple valid pairs, output the first one found following the order of traversal.
inputFormat
The input is provided via standard input (stdin) in the following format:
- The first line contains an integer \(n\) denoting the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array \(a\).
- The third line contains an integer \(T\) which is the target sum.
outputFormat
Print two space-separated integers on a single line representing the indices \(i\) and \(j\). If no valid pair exists, print -1 -1
.
4
2 7 11 15
9
0 1