← All problems

Two Sum II — Sorted Input

medium

Given a 1-indexed array of integers numbers already sorted in ascending order, find two numbers that add up to target. Return their indices (1-indexed) as [i, j] with i < j.

Use O(1) extra space — the sorted order is the hint that two pointers beat a hash map here.

Example

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