#K94942. Find Two Sum Indices
Find Two Sum Indices
Find Two Sum Indices
You are given an integer N representing the size of an array, an integer T which is the target sum, and an array of N integers. Your task is to find two distinct indices i and j (0-indexed) such that
[ arr[i] + arr[j] = T ]
If such a pair exists, output the pair of indices separated by a space. Otherwise, output -1
.
For example, if N = 5, T = 9
and arr = [2, 7, 11, 15, 1]
, then one valid answer is 0 1
because 2 + 7 = 9
.
inputFormat
The input is given via standard input (stdin
) and consists of two lines:
- The first line contains two integers N and T, where N is the number of elements in the array and T is the target sum.
- The second line contains N space-separated integers representing the elements of the array.
It is guaranteed that the array has at least one element.
outputFormat
Output via standard output (stdout
):
- If a pair of indices i and j exist such that
arr[i] + arr[j] = T
, print them separated by a space. - If no such pair exists, print
-1
.
5 9
2 7 11 15 1
0 1
</p>