Follow a deterministic sequence at two speeds to detect a cycle without storing every visited state.
THE MENTAL MODEL
When should this come to mind?
Follow a deterministic sequence at two speeds to detect a cycle without storing every visited state.
Cycle detectionLinked-list loopsRepeated state transformation
What makes it work
Each state must have one deterministic successor. Handle termination before advancing through missing links. Happy Number always produces another integer.
When to choose something else
Branching graphs need a visited set or graph traversal; there is no single successor sequence to follow.
See the pattern in action
Change the input. Follow the state. Make it yours.