#C12621. Two Sum Problem
Two Sum Problem
Two Sum Problem
You are given a list of integers and a target integer. Your task is to find exactly two distinct elements in the list whose sum equals the target. It is guaranteed that there is exactly one solution. You should output the indices of these two numbers.
The problem can be formalized as follows: Given an array \(A = [a_0,a_1,\dots,a_{n-1}]\) and an integer \(T\), find indices \(i\) and \(j\) such that \(a_i+a_j=T\) and \(i\neq j\).
Note: The indices returned should be based on 0-indexing.
inputFormat
The input is read from stdin and consists of three lines:
- The first line contains a single integer \(n\) denoting the number of elements in the list.
- The second line contains \(n\) space-separated integers representing the list.
- The third line contains an integer \(T\), the target sum.
outputFormat
Output to stdout a single line containing two space-separated integers: the indices of the two numbers such that their sum equals the target.
## sample4
2 7 11 15
9
0 1
</p>