Two Sum II (Sorted)

easy

Find two numbers in a sorted array that add up to target

Two Sum II (Sorted Array)

Key Insight

In sorted array: sum < target → move left right, sum > target → move right left

Step 1Setup: Find two numbers summing to 9
Target: 9
left
2
0
7
1
11
2
right
15
3
converge

Array is sorted. Place left pointer at start, right at end.

1 / 5

Learn the Pattern

Practice the Code

Step-by-Step Walkthrough: Two Sum II (Sorted Array)

In sorted array: sum < target → move left right, sum > target → move right left

  1. Setup: Find two numbers summing to 9

    Array is sorted. Place left pointer at start, right at end.

  2. Check Sum

    2 + 15 = 17. Sum is greater than 9, so move right pointer left.

  3. Move Right Pointer

    Right moves to index 2. Now check 2 + 11.

  4. Continue Moving

    Still too large. Right moves to index 1.

  5. Found!

    2 + 7 = 9. Return indices [0, 1].