← Visualizers
Linked List Two Pointers LeetCode 19

Remove Nth Node From End / visualized

Remove the n-th node from the end in a single pass, no length count. Give fast an n-node head start; once the gap is set, walk slow and fast together — when fast hits the end, slow is right before the node to remove.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

dummy slow 🐢 fast 🐇 node to remove
O(n) time · O(1) space  ·  the dummy node exists purely so "removing the head" isn't a special case.