Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use two pointers: slow moves one step at a time, fast moves two steps. If a cycle exists, fast will eventually lap slow and they will meet. If fast reaches null, there is no cycle.
In a cycle, the fast pointer closes the gap by one node per step. Since the gap shrinks monotonically, the two pointers are guaranteed to meet within one full traversal of the cycle.
Updated Feb 2026