Loading practice problems…
Loading your practice workspace…
Loading code editor…
23 / 29
Sign in
Algorithms/Linked List

Remove Nth Node From End of List

medium30 min

Given the head of a singly linked list and an integer n, remove the nth node counted from the end.

Return the list's head after the removal. Each node has the shape { val, next }.

Example 1

Inputhead = [1, 2, 3, 4, 5], n = 2

Output[1, 2, 3, 5]

Example 2

Inputhead = [1], n = 1

Output[]

Constraints

  • 1 ≤ n ≤ number of nodes ≤ 30
  • The list contains at least one node.
Linked ListTwo Pointers