Two Sum II (Popular) Problem

Two Sum II (Popular) Problem — ExecCode Medium DSA Practice

Solve the Two Sum II (Popular) problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

The array is sorted, so solve Two Sum without a hash map. Keep left on the smallest candidate and right on the largest candidate, then shrink the search range based on the current sum.

Examples

Input numbers = [1,3,4,6,8,11], target = 10; Output [3,4]. Input numbers = [2,3,4], target = 6; Output [1,3]

Constraints

1 ≤ n ≤ 10^5

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