
Recognize the technique
Read the recognition cues and a worked example. Write the input conditions that make the technique useful.
ExampleTwo pointers can find a pair in a sorted array. Explain what would break if the input were unsorted.
Predict the next visual step
Open the visualization and step through it. Before advancing, predict which pointer, node, or state will change and why.
ExampleFor [1, 2, 4, 6] and target 8, start with 1 + 6. Because 7 is too small, move the left pointer. Now 2 + 6 equals 8.
Complete a drill and transfer it
Answer a lesson drill, then use Practice This Technique where offered. Write the invariant before implementing the related challenge.
ExampleExplain why moving the left pointer discards no valid pair when the sum is too small. Apply that reasoning on a different sorted array.
Check your work
You can predict a step before the visualization shows it and solve a related input by explaining the same invariant.
Try it yourself
Open an array pattern lesson and trace a case with duplicates. For a sorted pair search on [1, 2, 2, 5] with target 4, predict both pointer moves before pressing next.
- What to look for
- Start at 1 + 5, move the right pointer because the sum is too high, then move the left pointer when 1 + 2 is too low. The two occurrences of 2 are at distinct indices.