Skip equal neighbors after a hit05.06
After you record a pair, advance L while a[L] equals the used left, and R while a[R] equals the used right. For a fixed i, skip equal i after that i is done.
Skip after a hit, not before. Stop skipping when L >= R. The first copy of a value is the one you used.
Same skill, three traces. Read all three before you try it.
01skip extra 4 - given
a = [1, 4, 4, 9],target=5- walk
L=0,R=2:1+4=5hitR-=1whilea[R]==4→R=0L+=1→L=1- result
L=1,R=0· (1,4) once
02skip extra 1 - given
a = [1, 1, 4, 9],target=10- walk
L=0,R=3:1+9=10hitL+=1whilea[L]==1→L=2- result
L=2,R=2· (1,9) once
03no extras - given
a = [1, 4, 9],target=10- walk
L=0,R=2hitL+=1,R-=1neighbors
4≠1and4≠9- result
L=1,R=1
skipAfterHit(a, target).a is a sorted array of integers. target is the pair sum. L is the left index. R is the right index. Duplicates if present are adjacent.After each hit print
L and R once duplicates are skipped. Return nothing.On
[1, 4, 4, 9] target 5, [1, 1, 4, 9] target 10, and [1, 4, 9] target 10.constraintsa is sorted non-decreasing, length ≥ 2. A hit exists at the current L, R. Duplicates if present are adjacent.
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.