Dashboard
LC #167

Two Sum II - Input Array Is Sorted

Pattern · ?AmazonGoogleApple

Problem

Find two numbers in a sorted array that add up to a target. Return their 1-indexed positions.

Constraints

  • 2 ≤ n ≤ 3 × 10⁴
  • -1000 ≤ numbers[i] ≤ 1000
  • Sorted in non-decreasing order
  • Exactly one solution guaranteed

Example

Input
numbers = [2, 7, 11, 15], target = 9
Output
[1, 2]
Why
numbers[1] + numbers[2] = 2 + 7 = 9 (1-indexed)

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗