Two Sum II - Input Array Is Sorted
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.
Return the indices of the two numbers, `[index1, index2]`, added by one as an integer array `[index1, index2]` of length 2.
Constraints
- 2 <= len(numbers) <= 3 * 10^4
- -1000 <= numbers[i] <= 1000
- numbers is sorted in non-decreasing order.
- Exactly one valid solution exists.
Progressive Hint Ladder
Since the array is already sorted, you can compare the sum of the smallest and largest available numbers.
Python 3.12 (Direct WASM Runtime)Shortcut: Cmd/Ctrl + Enter
Loading Monaco Python Editor...
Test Cases
Input:
{
"numbers": [
2,
7,
11,
15
],
"target": 9
}
Expected Output:
[1,2]