Remove Nth Node From End of List
Remove the n-th node from the end of a singly linked list and return its head.
Progress cannot be saved in this browser, so completed lessons will reset when you leave.
Lesson notes
Try it before you watch
Restate the problem in your own words, list the edge cases, and sketch a solution with its running time. Then play the video and compare.
Reveal the key idea
Put a dummy node before the head and move a fast pointer n steps ahead. Advance both pointers until fast reaches the end; slow then sits just before the node to delete.
Pattern: Linked lists. Re-wire next pointers carefully; a dummy head and fast/slow pointers remove most edge cases.
Complexity
| Measure | Bound |
|---|---|
| Time | O(L) |
| Extra space | O(1) |
Walkthroughs often start from a simpler approach first; aim to reach these bounds. New to Big-O? Read understanding algorithmic complexity.