K12
Two Sum II - Sorted Array
Problem Statement & Objective
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], as a 1-indexed array.
You may not use the same element twice. Exactly one solution is guaranteed.
Function Signature (Python)
two_sum_sorted(nums: list[int], target: int) -> list[int]Input & Output Contract
Output Rule:1-indexed integer array [index1, index2] where index1 < index2.
System Constraints
2 <= sayilar.length <= 3 * 10^4
-1000 <= sayilar[i] <= 1000
sayilar is sorted in non-decreasing orderExample Execution Walkthrough
sayilar = [2, 7, 11, 15], hedef = 9
2 + 7 = 9 -> result [1, 2]Example Test Scenarios (3)
Example 1
Input:
[[2,7,11,15],9]Expected Output:
[1,2]Example 2: Uçlar
Input:
[[2,3,4],6]Expected Output:
[1,3]Example 3: Negatif Değer
Input:
[[-1,0],-1]Expected Output:
[1,2]