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 a dummy node before the head to handle edge cases. Advance the fast pointer n+1 steps ahead so there is a gap of n nodes between fast and slow. Move both until fast reaches null. Slow is now just before the target node, so skip it.
By maintaining a fixed gap of n nodes between fast and slow, when fast reaches the end of the list, slow is positioned exactly one node before the nth-from-end node, allowing a simple pointer rewire to remove it.
Updated Feb 2026