Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Remove the Nth node from the end

Remove the nth node from the end of a singly linked list using the two-pointer technique (fast & slow).

Python practice15 minLinked ListsIntermediateLast updated March 27, 2026

Problem statement

Given a list of values representing a singly linked list and an integer n, remove the nth node from the end of the list and return the resulting list of values. You must do this in one pass using the two-pointer (fast and slow) approach by first converting the input list to a linked-list, performing the removal, then converting back.

Task

Implement an efficient algorithm that removes the nth node from the end of a linked list in a single pass and returns the resulting list.

Examples

Basic removal

Input

[1, 2, 3, 4, 5], 2

Output

[1, 2, 3, 5]

The 2nd node from the end is 4. Removing it yields [1,2,3,5].

Input format

Two arguments: a Python list of integers representing node values, and an integer n (1-based) indicating which node from the end to remove.

Output format

A Python list of integers representing the linked list after removal.

Constraints

1 <= n <= length of list. List length can be up to 10^5. Aim for O(L) time and O(1) extra space (excluding the output).

Samples

Sample 1

Input

[1,2,3,4,5], 2

Output

[1,2,3,5]

Remove the 2nd from end (4).