4. Two sum
Given a list of integers nums and a target, write twoSum nums target. It returns some (i, j) when i < j and the elements at positions i and j add up to target, and none when no such pair exists. Positions count from 0.
When several pairs work, return the one with the smallest i, and among those the smallest j.
Examples
Input: twoSum [2, 7, 11, 15] 9Output: some (0, 1)Input: twoSum [3, 2, 4] 6Output: some (1, 2)Input: twoSum [1, 2] 7Output: none
Submitting also runs 8 hidden tests.
Constraints
- Hidden tests include negative numbers, repeated values and lists of 200 elements.
Without the Pass you can run 3 Pass problems against their examples. Submitting, the hints and the editorial come with the Academy Pass. The daily problem and one Medium problem a week are open to every account.
\to in the editor, or click:Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.