Paired Sum in a Sorted Array
L3 Easy Two Pointers
When an array is already sorted, two pointers — one at each end — can find a pair that hits a sum in a single pass, without a dictionary.
You are given an array of integers numbers, sorted in non-decreasing order, and a target. Exactly two different entries add up to target. Return their 1-based positions (starting at 1) as a two-element array, in any order. You may not reuse the same index twice.
Examples
▸ numbers = [2, 7, 11, 15], target = 9
→ [1, 2]
▸ numbers = [2, 3, 4], target = 6
→ [1, 3]
▸ numbers = [-1, 0], target = -1
→ [1, 2]