Decide which end to advance02.04
The decision reads a[L] and a[R], usually their sum. Move the end whose value you have consumed. Do not move both unless the algorithm says so.
Exactly one of L or R changes per decision. After the move, name the new indices. Too-small sum advances L. Too-large sum advances R. A hit does not discard an end.
Same skill, three traces. Read all three before you try it.
01sum too large - given
a = [1, 4, 9],target=8,L=0,R=2- walk
L=0,R=21+9=10>8advance
R- result
L=0,R=1
02sum too small - given
a = [1, 4, 9],target=13,L=0,R=2- walk
L=0,R=21+9=10<13advance
L- result
L=1,R=2
03equal - given
a = [1, 4, 9],target=10,L=0,R=2- walk
L=0,R=21+9=10hitdo not pick an end to discard
- result
L=0,R=2· pair found
decideEnd(a, L, R, target).a is a sorted array of integers. L is the left index. R is the right index. target is the pair sum you want.Move
L if the sum is too small, R if too large, neither on a hit. Print which pointer moved and the new indices.On sorted
[1, 4, 9] from L=0, R=2: target 8 moves R, target 13 moves L, target 10 hits and stays.constraintsa is sorted non-decreasing, length ≥ 2. Start at L = 0, R = n-1.
- Container With Most Water0/3 skills ready · two pointers · mediumopen
- Container With Most Water0/3 skills ready · two pointers · mediumopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.