THE INSPECTION RAILTWO
TWO
POINTERS.
03PROBLEMS
Two positions. One reason to move.
Learn what you can safely leave behind.
00 / The idea before the code
Don’t ask “which pointer moves?” Ask “what can this move safely rule out?”
Start at two useful positions. Inspect what they tell you. Move a boundary only when you can explain why the discarded work cannot change the answer.
For a palindrome, matched edges are settled. For water, the shorter wall is a ceiling. For 3Sum, sorted order gives each move a direction.
WATCH THE INVARIANT01 / 03
PAIRS0
COMPARISONmatch
↳
Everything outside these pointers has been verified. The inside is still undecided.
YOUR TURN · PREDICT THE MOVE
These two characters match. What have we proved?
CHECK THE IDEA
The outside letters of “abca” match. Can we stop?
Three scenes. One pattern.
LEARN → PREDICT → RECALL02
The limiting wall
Container With Most Water
Discover what you can safely leave behind.
8 minFinish the primer ↑
Give movement a direction.
In sorted values, moving left forward makes its value larger or equal. Moving right backward makes its value smaller or equal.
−5−2035