Given an array of integers nums and an integer target, find two distinct indices i and j such that nums[i] + nums[j] == target. Every input has exactly one solution, and you may not use the same element twice.
Line 1: space-separated integers (the array nums).
Line 2: a single integer target.
A single line containing two space-separated integers i j (0-indexed) such that i < j and nums[i] + nums[j] == target.
Example 1
Input
2 7 11 15 9
Expected
0 1
Explanation
nums[0] + nums[1] = 2 + 7 = 9, so the indices (0, 1) are returned in ascending order.
Example 2
Input
3 2 4 6
Expected
1 2
Explanation
nums[1] + nums[2] = 2 + 4 = 6.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →