Skip to main content

37. Remove Nth Node From End of List

mediumAsked at Plaid

Remove the nth node from the end of a linked list in one pass. Plaid asks this as a two-pointer baseline before harder windowed-removal problems on transaction-history lists.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Plaid loops.

  • Glassdoor (2025)Plaid SWE II OA.
  • LeetCode Discuss (2026)Plaid one-pass list problem.

Problem

Given the head of a linked list, remove the nth node from the end of the list and return its head. Follow up: could you do this in one pass?

Constraints

  • The number of nodes in the list is sz.
  • 1 <= sz <= 30
  • 0 <= Node.val <= 100
  • 1 <= n <= sz

Examples

Example 1

Input
head = [1,2,3,4,5], n = 2
Output
[1,2,3,5]

Example 2

Input
head = [1], n = 1
Output
[]

Approaches

1. Two-pass count then delete

First pass to count, second pass to find the (count - n)th node and remove its successor.

Time
O(n)
Space
O(1)
function removeNthFromEnd(head, n) {
  let len = 0;
  for (let p = head; p; p = p.next) len++;
  const dummy = { next: head };
  let p = dummy;
  for (let i = 0; i < len - n; i++) p = p.next;
  p.next = p.next.next;
  return dummy.next;
}

Tradeoff: Linear time but two passes. Fine for correctness.

2. Two pointers with n-step lead

Fast pointer leads by n. When fast hits the end, slow is at the node before the one to remove.

Time
O(n)
Space
O(1)
function removeNthFromEnd(head, n) {
  const dummy = { next: head };
  let slow = dummy, fast = dummy;
  for (let i = 0; i < n; i++) fast = fast.next;
  while (fast.next) { slow = slow.next; fast = fast.next; }
  slow.next = slow.next.next;
  return dummy.next;
}

Tradeoff: Single pass. The dummy head handles the edge case where head itself is removed.

Plaid-specific tips

Plaid grades this on the dummy-head pattern because removing the head is the edge case that trips most candidates. Bonus signal: explain why fast starts n steps ahead — the gap stays constant, so when fast hits null, slow is exactly n positions back.

Common mistakes

  • Forgetting the dummy head — removing the first node breaks the function.
  • Off-by-one in the gap (n vs n+1).
  • Looping while fast (not fast.next) — overshoots and leaves slow at the node to remove, not the node before.

Follow-up questions

An interviewer at Plaid may pivot to one of these next:

  • Remove the kth-to-last node where k is given.
  • Remove duplicates from a sorted linked list (LC 83).
  • Remove all nodes with a given value (LC 203).

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why a dummy head?

If head is the node to remove, you need a 'previous' pointer that doesn't exist. The dummy provides that.

Why does the gap-of-n trick work?

When fast.next is null, fast is at the last node. Slow is n positions behind, so slow.next is the nth from the end.

Practice these live with InterviewChamp.AI

Drill Remove Nth Node From End of List and other Plaid interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →