#K82372. Find Two Sum Indices
Find Two Sum Indices
Find Two Sum Indices
You are given an integer array and an integer target. Your task is to find two distinct indices i and j (with i < j
) such that:
\( nums[i] + nums[j] = target \)
If such a pair exists, output the two indices separated by a space. If no such pair exists, output -1
.
Note: The array uses 0-indexing. It is guaranteed that at most one valid pair exists in each test case.
inputFormat
The first line contains two integers n
and target
separated by a space, where n
is the number of elements in the array.
The second line contains n
integers separated by spaces representing the elements of the array.
outputFormat
If a valid pair exists, output two integers i and j (separated by a space) denoting the indices of the elements that add up to target
. Otherwise, output -1
.
5 11
3 2 4 7 1
2 3
</p>