#C2066. Two Sum Problem
Two Sum Problem
Two Sum Problem
You are given an array of integers and an integer target. Your task is to find and return the indices of the two numbers in the array such that they add up to the target. It is guaranteed that exactly one solution exists.
Formally, given an array \( a = [a_0, a_1, \dots, a_{n-1}] \) and an integer \( T \), find indices \( i \) and \( j \) (with \( i < j \)) such that:
\[ a_i + a_j = T \]You may assume that each input would have exactly one solution, and you may not use the same element twice.
Note: The indices in your output should be separated by a space.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- The first line contains a single integer ( n ) representing the number of elements in the array.
- The second line contains ( n ) space-separated integers representing the array values.
- The third line contains a single integer representing the target sum ( T ).
outputFormat
Output to standard output (stdout) two integers separated by a space, which are the indices of the two numbers such that they add up to the target.## sample
4
2 7 11 15
9
0 1