Back to problems Solve on LeetCode →

Two Sum II — Input Array Is Sorted

LeetCode 167 • Medium • Two Pointers

Input: numbers = [1, 3, 4, 5, 7, 11], target = 9  →  Output: [3, 4]
Given a 1-indexed sorted array, find two numbers that add up to target. Return their indices.

TimeO(n)single pass
SpaceO(1)two pointers
Left: Right: Sum:
Left pointer
Right pointer
Found pair
Left
Right
Sum
Result
pending
Ready
Press Play to watch two pointers converge on the target sum, or Step to advance one operation.
The left pointer starts at the beginning and the right pointer starts at the end.