Linked List Cycle
Return whether a linked list contains a cycle.
Why does this pattern fit?
Restate the exact job
Return whether a linked list contains a cycle.
A fast pointer eventually laps a slow pointer only inside a cycle.
O(n) time · O(1) space
Comparing node values instead of node identity produces false positives.
How to solve Linked List Cycle
The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.
What the question asks
Return whether a linked list contains a cycle.
Why Linked-list rewiring fits
A fast pointer eventually laps a slow pointer only inside a cycle.
State to maintain
Slow moves one edge; fast moves two.
Transition
Advance while fast and fast.next exist; equal pointers prove a cycle.
Time and space
O(n) time · O(1) space
Counterexample to the tempting mistake
Comparing node values instead of node identity produces false positives.
Prove it again tomorrow
Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.