12. Two Sum II (Sorted Input)

numbers is sorted in non-decreasing order. Find the two numbers that add up to target and return their positions 1-indexed as [index1, index2] with index1 < index2. Exactly one solution exists. Use only O(1) extra space.

Example 1

Input: numbers = [1,3,4,5,9], target = 10
Output: [1,5]
Explanation: 1 + 9 = 10, at positions 1 and 5.

Example 2

Input: numbers = [-4,-1,0,5], target = -5
Output: [1,2]
Hint 1

Start with the smallest and largest numbers.

Hint 2

If the sum is too small, only moving the left pointer can increase it.

Two PointersBinary Search