Problem
FAANG · LeetCode #167

Two Sum II — Sorted Array — three-stage drill

1The ProblemMedium

Two Sum II — Sorted Array

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

sorted array · find a pair summing to910314253741154 + 5 = 9 ✓return[3, 4]1-indexed
Examples
[1,3,4,5,7,11], t=9→ [3,4][1,3,4,5], t=20→ []
2The PatternTIME O(n) · SPACE O(1)

Two Pointers

Converging from both ends, comparing as they meet.

loop while left < right · move both inwarda0b1c2d3e4f5g6left›right‹compare → if equal, move both inward
Problems using this pattern
3The SolutionRESULT → [3, 4]

Step through it

target = 91031425374115leftright
Initialize: left at 0, right at 5. target = 9.
Step 1 / 6
Arrow keys to navigate · escape to reset

All problems by pattern

Backtracking

Recursive Descent