dsa · medium
Two Sum II
numbers is sorted non-decreasing. Return the 1-based indices of two values that sum to target. Exactly one solution exists. You may not reuse the same slot twice.
Arguments
numbers— sorted non-decreasing arraytarget— required pair sum
Example
numbers = [2,7,11,15], target = 9 → [1,2].
Constraints
2 <= numbers.length <= 3*10^4 numbers is non-decreasing Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [2,7,11,15] 9 Expected: [1,2]
Example 2
Input: [2,3,4] 6 Expected: [1,3]
Example 3
Input: [-1,0] -1 Expected: [1,2]