Two Sum II - Input Array Is Sorted
Find two numbers that add up to a specific target number in a sorted array. Return 1-based indices.

30:00

Two Sum II - Input Array Is Sorted
medium
Topics
Companies

Find two numbers that add up to a specific target number in a sorted array. Return 1-based indices.

Example 1:
Input: {"numbers":[2,7,11,15],"target":9}
Output: [1,2]
Constraints:
  • 2numbers.length3×1042 \leq \text{numbers.length} \leq 3 \times 10^4

  • 1000numbers[i]1000-1000 \leq \text{numbers}[i] \leq 1000

  • numbers is sorted in non-decreasing order.

  • 1000target1000-1000 \leq \text{target} \leq 1000

  • The tests are generated so that there is exactly one solution.

Input
arr ={"numbers":[2,7,11,15],"target":9}
Target

9

vs

Current Sum (L+R)

?

2

L

1

7

2

11

3

15

R

4

Variables
VariableValue
l0
r3
DepthFunction Call
Stack empty
0/11