Remove Nth Node From End of List
Part of Practice: Gaps, Clones & Carries
Given the head of a linked list and an integer n, delete the n-th node counting from the end (n = 1 means the last node) and return the head of the updated list.
n is always valid — between 1 and the list's length. The list has at least one node and at most 30. The follow-up asks for a single pass over the list, which is the expected interview solution.
Examples
- Input:
- head = [1, 2, 3, 4, 5], n = 2
- Output:
- [1, 2, 3, 5]
The 2nd node from the end is 4; removing it links 3 directly to 5.
- Input:
- head = [1], n = 1
- Output:
- []
Removing the only node leaves an empty list.
- Input:
- head = [1, 2], n = 2
- Output:
- [2]
The 2nd from the end is the head itself.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.