#K73037. Two Sum Problem
Two Sum Problem
Two Sum Problem
Given an array of integers and a target value, your task is to find two distinct indices such that the numbers at those indices add up to the target. You may assume that each input has exactly one solution and that you may not use the same element twice.
The solution should be efficient, ideally using a hash table approach. In other words, find indices i and j (with i < j) such that:
\( nums[i] + nums[j] = target \)
Input is provided via standard input (stdin) and output should be written to standard output (stdout) as described below.
inputFormat
The input consists of three lines:
- The first line contains an integer n denoting the number of elements in the array.
- The second line contains n space-separated integers representing the array.
- The third line contains a single integer representing the target value.
outputFormat
Output two space-separated integers representing the indices of the two numbers that add up to the target. It is guaranteed that a unique solution exists.
## sample4
2 7 11 15
9
0 1