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 starting at the head. Move slow one step and fast two steps on each iteration. When fast reaches the end, slow is at the middle. For even-length lists, this returns the second of the two middle nodes.
The fast pointer traverses the list at double speed, so when it finishes the slow pointer has covered exactly half the distance, landing on the middle node.
Updated Feb 2026