167. Two Sum II - Input Array Is Sorted

Practice Two Sum II - Input Array Is Sorted for free on NudgeCode: Medium, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

numbers is sorted in non-decreasing order. Find the two different positions whose values add up to target and return them as [index1, index2] with index1 < index2, counting positions from 1. Exactly one pair works. Use only O(1) extra space.

Example

numbers = [2,7,11,15], target = 9  ->  [1,2]
numbers = [2,3,4], target = 6      ->  [1,3]

Constraints