52 / 75
M

Remove Nth Node From End of List

#52
linked-listtwo-pointers

Use two pointers with n-gap to find node before target, then skip target node.

Example:

Input:head=[1,2,3,4,5], n=2
Output:[1,2,3,5] (removed 4)

Common Mistakes:

  • Not using dummy node (fails when removing head)
  • Wrong gap size (should be n+1 to land before target)
  • Trying to find length first (not one-pass solution)
  • Off-by-one errors with pointer positioning

Notes:

Classic two-pointer technique. Time O(L) one pass, Space O(1). Dummy node simplifies edge cases.

52/75
Remove Nth Node From End of List