Description
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number.
Examples
Input:
numbers = [2,7,11,15], target = 9Output:
[1,2]Explanation:
numbers[0] + numbers[1] = 9.
Input:
numbers = [-1,0], target = -1Output:
[1,2]Explanation:
Works with negative numbers.
Input:
numbers = [1,3,3,6,8], target = 6Output:
[1,4]Explanation:
The sum of numbers[0] + numbers[3] = 1 + 6 = 6. Note that skipping the duplicate 3's at indices 1 and 2, and find the valid pair at positions 1 and 4 (1-indexed).
Constraints
- •
2 ≤ numbers.length ≤ 3 × 10⁴ - •
-1000 ≤ numbers[i] ≤ 1000 - •
numbers is sorted in non-decreasing order.