Remove Nth Node From End of List Problem

Remove Nth Node From End of List Problem — ExecCode Easy DSA Practice

Solve the Remove Nth Node From End of List problem on ExecCode. Free online easy DSA practice in Linked List. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given the head of a linked list, remove the nth node from the end of the list and return its head. Indexing is 1-based from the end: n = 1 removes the last node. Handle edge cases such as removing the head when the list length equals n. Prefer a one-pass two-pointer solution when possible.

Examples

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

Constraints

1 ≤ list length ≤ 30 1 ≤ n ≤ list length

Practice Remove Nth Node From End of List free on ExecCode. Browse DSA problems, topic map, and placement guides.