Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Two Sum II - Input Array Is Sorted

Medium

Topics
ArrayTwo PointersBinary Search

Given a 1-indexed array numbers sorted in non-decreasing order, find two numbers adding up to target. Return [index1, index2] (1-indexed) with index1 < index2.

Exactly one solution exists; use only constant extra space.

Example 1

Input:  numbers = [2,7,11,15], target = 9
Output: [1,2]

Example 2

Input:  numbers = [2,3,4], target = 6
Output: [1,3]

Constraints

  • 2 <= numbers.length <= 3*10^4
  • numbers is sorted non-decreasing.
  • Exactly one solution.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access