Two Sum
You are given an array of integers and a target sum.
Find two distinct positions whose values add up to the target.
It is guaranteed that exactly one valid pair exists.
Input
The first line contains two integers n and target, the size of the array and the target sum.
The second line contains n integers: a1,a2,…,an.
Output
Print two space-separated integers i and j (i<j), the 1-indexed positions of a pair such that ai+aj=target.
Constraints
- 2≤n≤2⋅105
- −109≤ai≤109
- −2⋅109≤target≤2⋅109
- Exactly one valid pair exists.
Example 1
4 9
2 7 11 15
1 2
Example 2
5 6
3 2 4 8 10
2 3
Example 3
5 10
-1 4 9 11 2
1 4
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.