Loading content...
You are provided with a 1-indexed integer array numbers that is pre-arranged in ascending order (non-decreasing). Your objective is to identify two distinct elements within this array that, when summed together, equal a specified target value.
Formally, you must find positions first and second such that 1 ≤ first < second ≤ numbers.length and numbers[first] + numbers[second] = target.
Return an array containing these two 1-based indices [first, second].
Key Constraints:
This problem tests your ability to exploit the inherent ordering of data to achieve optimal space efficiency while maintaining excellent time performance.
numbers = [2, 7, 11, 15]
target = 9[1, 2]The values at positions 1 and 2 are 2 and 7 respectively. Their sum is 2 + 7 = 9, which matches the target. Hence, we return [1, 2].
numbers = [2, 3, 4]
target = 6[1, 3]The element at position 1 is 2, and the element at position 3 is 4. Since 2 + 4 = 6 equals the target, we return [1, 3].
numbers = [-1, 0]
target = -1[1, 2]The array contains -1 at position 1 and 0 at position 2. Adding them yields -1 + 0 = -1, matching the target value.
Constraints