#K43127. Two Sum
Two Sum
Two Sum
Given a list of integers and a target integer \(T\), find the indices of two distinct elements that add up to \(T\). It is guaranteed that each input has exactly one solution, and you may not use the same element twice. Use an efficient algorithm (e.g., hash table) to achieve an average time complexity of \(O(n)\).
For example, if the input array is [2, 7, 11, 15] and \(T=9\), the expected output is indices [0, 1] since \(2+7=9\).
inputFormat
The input is read from stdin. The first line contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers. The third line contains a single integer (T), the target sum.
outputFormat
Output to stdout two space-separated indices of the elements whose sum is (T). If no such pair exists, output nothing.## sample
4
2 7 11 15
9
0 1