Linked listsLeetCode 19

Lesson 6 of 76

Remove Nth Node From End of List

Remove the n-th node from the end of a singly linked list and return its head.

Watch on YouTube

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

Cost of the standard optimal approach for Remove Nth Node From End of List
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.