Skip to content
Preptima
mediumCodingEntryMidSenior

Remove the nth node from the end of a singly linked list in a single pass.

4 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Run one pointer n nodes ahead of another, then advance both until the leader reaches the last node, leaving the follower on the predecessor of the node to unlink.A dummy node in front of the head is what removes the separate case for deleting the head itself.

Was this answer helpful?

Likely follow-ups

  • Remove every node with a given value instead. Does the sentinel still earn its place?
  • The list is doubly linked. Does the two-pointer walk still buy you anything?
  • Remove the middle node, where middle is defined as the lower of the two for an even length.
  • You must not use the length and you must not modify any node's value. Which of your options does that rule out?

Related questions

Related Topics