#C1018. Two Sum Problem
Two Sum Problem
Two Sum Problem
You are given an array nums of integers and an integer target. Your task is to find two distinct indices i and j in the array such that
$$nums[i] + nums[j] = target$$
You may assume that each input has exactly one solution, and you may not use the same element twice. The answer can be returned in any order.
This is a classic problem that tests your ability to use efficient data structures (e.g. hash tables) to achieve an optimal solution.
inputFormat
The first line contains an integer n, representing the number of elements in the array. The second line contains n space-separated integers representing the elements of the array. The third line contains one integer representing the target value.
outputFormat
Output a single line containing the two 0-indexed positions separated by a space.## sample
4
2 7 11 15
9
0 1
</p>