#K47362. Pair Sum Indices
Pair Sum Indices
Pair Sum Indices
You are given an array of integers nums and a target integer target. Your task is to find two distinct indices \(i\) and \(j\) such that:
[ nums[i] + nums[j] = target ]
If such a pair exists, output the indices \(i\) and \(j\) (0-indexed) separated by a space. Otherwise, output -1.
Note: In each test case, the first two integers denote \(n\) (the number of elements in the array) and \(target\), followed by \(n\) space-separated integers representing the array elements. All input should be read from standard input (stdin) and output to standard output (stdout).
inputFormat
The input consists of a single line containing \(n\) and \(target\) followed by \(n\) space-separated integers representing the array \(nums\).
For example: 5 9 2 7 11 15 1
represents an array of 5 integers, and the target sum is 9.
outputFormat
If a pair of indices \(i\) and \(j\) exists such that \(nums[i] + nums[j] = target\), print the two indices separated by a space. If no such pair exists, output -1
.
5 9
2 7 11 15 1
0 1