#C12726. Find Two Sum Indices
Find Two Sum Indices
Find Two Sum Indices
Given an array of integers and a target integer \(T\), find two distinct indices \(i\) and \(j\) such that \(nums[i] + nums[j] = T\). If no such pair exists, return an empty list. Note that each input is guaranteed to have exactly one solution, except when no solution is possible.
Note: You cannot use the same element twice. The answer must be output in the format of a Python list (e.g., [0, 1]
or []
if no valid pair exists).
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 elements of the array). The third line contains the target integer (T).
outputFormat
Output a list containing two indices in the format [i, j] if the pair is found, otherwise output [] if no such pair exists.## sample
4
2 7 11 15
9
[0, 1]