ExamAdda Logo

Two Sum II Input Array Is Sorted

Easy

Given a 1-indexed array of integers numbers that is sorted in non-decreasing order, find two numbers such that they add up to a specific target number.

Return the indices of the two numbers (1-indexed) as an array of size 2.

You may assume that each input has exactly one solution, and you may not use the same element twice.

Your solution must use only constant extra space.

Example 1

Input

4
2 7 11 15
9

Output

1 2

Explanation

The numbers at indices 1 and 2 are 2 and 7.

Their sum is 9, so the answer is [1, 2].

Example 2

Input

3
2 3 4
6

Output

1 3

Explanation

The numbers at indices 1 and 3 are 2 and 4.

Their sum is 6, so the answer is [1, 3].

Constraints

2 ≤ numbers.length ≤ 3 × 10⁴
-1000 ≤ numbers[i] ≤ 1000
numbers is sorted in non-decreasing order.
There is exactly one solution.

Hints:

Hint 1

Since the array is already sorted, use one pointer at the beginning and another at the end.

Hint 2

If the current sum is smaller than the target, move the left pointer forward. If the current sum is larger than the target, move the right pointer backward until the target sum is found.

Follow-up

Similar Questions

  • Two Sum
  • 3Sum
  • 4Sum
  • Container With Most Water

 

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 4, 2026

Last updated

Aug 6, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output