Medium · Two pointers

Two Sum II: Sorted Input

You are given a list of integers sorted from smallest to largest, and a number, target. Two of them add up to target. Return their positions, counting from 1, smaller position first.

  • There is always exactly one such pair.
  • Positions count from 1, not 0.
  • Use no extra space beyond a few variables.
numbers = [2, 7, 11, 15]
target  = 9

→ [1, 2]   (2 + 7 = 9)
Record your take

No one has solved it yet.