#C8878. Find a Pair with a Given Sum
Find a Pair with a Given Sum
Find a Pair with a Given Sum
You are given an array of integers and a target sum ( T ). Your task is to determine if there exists any pair of distinct indices ( (i, j) ) such that ( nums[i] + nums[j] = T ). If such a pair exists, output the indices (with the index of the first occurrence coming first). Otherwise, output (-1 -1).
Note: Indices in the output should be zero-based. It is guaranteed that if a valid pair exists, the one with the smallest first index should be returned. In case of a tie, return the one with the smallest second index.
inputFormat
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 integer ( T ).
outputFormat
Output two space-separated integers representing the indices of the two numbers whose sum equals ( T ). If no such pair exists, output (-1 -1).## sample
4
2 7 11 15
9
0 1