#K77822. Pair Sum Indices
Pair Sum Indices
Pair Sum Indices
We are given an array of integers and a target value. The task is to determine whether there exists a pair of numbers in the array such that their sum equals the target. If such a pair exists, output the indices of these two numbers. If multiple valid pairs exist, return the first occurring pair. Otherwise, output an empty list, denoted as []
.
The mathematical condition for a valid pair (i, j) is given by: $$a_i + a_j = target$$, where (a_i) and (a_j) are elements of the array, and (i < j).
inputFormat
The input is read from standard input (stdin). The first line contains two space-separated integers: (n) (the number of elements in the array) and (target) (the target sum). The second line contains (n) space-separated integers representing the array elements.
outputFormat
The output is written to standard output (stdout). If a valid pair is found, output the two indices (0-indexed) separated by a space. If no such pair exists, output an empty list represented as []
.## sample
5 9
2 7 11 15 4
0 1