Course · Section 11: Working With Arrays · Lecture 149: Simple Array Methods
Given a **sorted** array `nums` and a `target`, return the 0-based indices `[i, j]` of the two numbers that add up to `target`. Exactly one solution exists. Example: `twoSum([1, 2, 4, 7], 6)` → `[1, 2]`.
+ 2 hidden tests run on Submit.
Two pointers start at the ends and move inward based on the sum versus target. O(n) time, O(1) space.
Run your code to see results.