#K49757. Find Pair with Given Sum
Find Pair with Given Sum
Find Pair with Given Sum
Given an array of integers and a target value \( T \), find the first pair of indices \((i, j)\) such that the sum of the elements \( nums[i] + nums[j] = T \). The "first" pair is defined as the one where the index \( i \) is as small as possible, and for the same \( i \), the index \( j \) is as small as possible. If no such pair exists, output -1 -1
.
Input Format: The first line contains an integer \( n \) representing the number of elements in the array. The second line contains \( n \) space-separated integers. The third line contains the target value \( T \).
Output Format: Output two integers representing the indices of the elements that sum to \( T \). If no valid pair exists, output -1 -1
. Indices are 0-based.
inputFormat
The first line contains an integer \( n \) — the number of elements in the array. The second line contains \( n \) integers representing the array elements separated by spaces. The third line contains an integer \( T \), the target sum.
outputFormat
Output two integers in a single line separated by a space. These integers are the indices \( i \) and \( j \) of the first pair whose elements sum to \( T \). If no such pair exists, output -1 -1
.
4
2 7 11 15
9
0 1
</p>