ASAPUtils Logo ASAPUtils
Week 5

Remove Nth Node From End

Remove Nth Node From End using a dummy node and fixed fast-slow gap, with the gap invariant, C++ and JavaScript implementations, one-pass complexity, head-deletion handling, and an interactive pointer trace.

The problem

Remove the nth node counted from the end of a singly linked list and return the possibly changed head.

1 -> 2 -> 3 -> 4 -> 5, n = 2 becomes 1 -> 2 -> 3 -> 5

Related Problems