1. Two Sum
EasyArrayHash Map
Given an array of integers and a target, find the two different positions whose values add up to the target. Exactly one such pair exists.
Input format
Line 1: n (the number of elements) Line 2: n space-separated integers Line 3: the target
Output format
Two 0-based indices i and j (i < j), separated by a space.
Example 1
Input
4 2 7 11 15 9
Output
0 1
Explanation: nums[0] + nums[1] = 2 + 7 = 9.
Example 2
Input
3 3 2 4 6
Output
1 2
Explanation: nums[1] + nums[2] = 2 + 4 = 6.
Constraints
2 ≤ n ≤ 10⁵ −10⁹ ≤ values, target ≤ 10⁹
Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.
Loading the MyLoginn IDE…