Two Sum II Sorted Problem

Two Sum II Sorted Problem — ExecCode Easy DSA Practice

Solve the Two Sum II Sorted problem on ExecCode. Free online easy DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.

Problem description

The array is already sorted. Find two 1-based indices whose values add to target. Start with the smallest and largest values: if the sum is too small, move left rightward; if it is too large, move right leftward.

Examples

Input numbers = [2,7,11,15], target = 9; Output [1,2]. Input numbers = [-5,-2,1,4,9,12], target = 7; Output [2,5]

Constraints

2 ≤ numbers.length ≤ 3×10⁴ -1000 ≤ numbers[i] ≤ 1000 numbers is sorted non-decreasing Each input has exactly one solution

Practice Two Sum II Sorted free on ExecCode. Browse DSA problems, topic map, and placement guides.