Stage 1 · Code
Arrays & Strings
Two Pointers
Opposite, same-direction, and fast-slow pointer techniques.
Opposite Pointers
Left pointer at start, right at end. Move toward each other based on comparison. Requires sorted array or known ordering property.
Same Direction
Both pointers move left-to-right. Fast pointer scans ahead, slow pointer marks position for writes. Used for in-place modifications, removing duplicates, partitioning.
Fast & Slow Pointers
Slow moves 1 step, fast moves 2 steps. Used for cycle detection (Floyd's algorithm), finding middle of linked list, detecting cycle start.
When to Use Each
| Type | Use When | Requires |
|---|---|---|
| Opposite | Pair sum, palindrome, container with most water | Sorted or monotonic property |
| Same direction | Remove duplicates, merge, partition, Dutch flag | In-place modification OK |
| Fast/slow | Cycle detection, middle element, cycle start | Linked list or cyclic structure |
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.