Loading practice problems…
Loading your practice workspace…
Loading code editor…
5 / 29
Sign in
Algorithms/Two Pointers

Two Sum II — Input Array Is Sorted

medium25 min

Given a one-indexed array of integers sorted in non-decreasing order and a target, find two different values that add up to the target.

Return their one-based indices as [index1, index2], with index1 smaller than index2.

Example 1

Inputnumbers = [2, 7, 11, 15], target = 9

Output[1, 2]

Example 2

Inputnumbers = [2, 3, 4], target = 6

Output[1, 3]

Constraints

  • 2 ≤ numbers.length ≤ 30,000
  • Exactly one solution exists.
Two PointersArrays