Skip to main content

Fast & Slow Pointers

Learn Fast & Slow Pointers (Arrays, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

The Fast & Slow (Tortoise and Hare) Pattern Two pointers start at the same place but move at different SPEEDS - typically slow moves 1 step and fast moves 2 steps per iteration. It's most famous for cycle detection in a linked list, but the same idea applies to arrays where values act as "next pointers" (each value tells you the next index to jump to). The key insight: if there's a cycle, the fast pointer will eventually lap the slow pointer and they will meet INSIDE the cycle - if there's no cycle, fast simply reaches the end first.

More lessons in Arrays