Skip to interview prep
Apexed

52. Remove the Nth Node From the End

MediumLinked lists

Remove the nth node from the end of the list in one pass and return the head.

A linked list is passed as ListNode objects with val and next. The tests write lists as arrays.

Example 1

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

Constraints

  • 1 ≤ n ≤ number of nodes ≤ 30

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Remove the Nth Node From the End — coding interview practice — Apexed