visual walkthrough
Remove Nth Node From End of List
A fixed gap between two pointers in one pass.
The idea
"n-th from the end" is easy once you know the length, but that takes a full pass first.
Instead, start a second pointer n + 1 nodes ahead and move both together. When the front one falls off the end, the back one is right before the node to remove.
Complexity
| approach | time | space |
|---|---|---|
| Count, then walk | O(L) | O(1) |
| Fixed gap | O(L) | O(1) |