cheetcode

11. Two Sum II Input Array Is SortedMedium

Find the 1-indexed positions of two numbers in a sorted array that add to the target.

Given a 1-indexed array of integers numbers sorted in non-decreasing order, find two numbers that add up to a specific target number.

Return the indices of the two numbers as a 1-indexed array of length 2.

Examples

Input: numbers = [2,7,11,15], target = 9
Output: [1,2]
Input: numbers = [2,3,4], target = 6
Output: [1,3]

Constraints

  • 2 <= numbers.length <= 30,000
  • -1,000 <= numbers[i], target <= 1,000
  • Exactly one solution exists.