Problem
You get head, the first node of a linked list, and an integer n. A linked list is a chain of nodes, and each node links to the next node.
Remove the nth node from the end of the list, and return the head of the changed list. The last node is the 1st node from the end.
Example 1
- Input:
- head = [4,7,1,9,3], n = 4
- Output:
- [4,1,9,3]
- Explanation:
- The 4th node from the end has the value 7.
Example 2
- Input:
- head = [8,2], n = 2
- Output:
- [2]
- Explanation:
- The 2nd node from the end is the first node, so the head changes.
Example 3
- Input:
- head = [5], n = 1
- Output:
- []
- Explanation:
- The list has only one node. After you remove it, the list is empty.
Constraints
- The number of nodes in the list is sz.
- 1 <= sz <= 30
- 0 <= Node.val <= 100
- 1 <= n <= sz
Follow-up
Can you remove the node with only one pass over the list?
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Meta
Leetcode 19. Remove Nth Node From End of List
Reported Oct 25, 2025 · 6 source reports
MID_LEVEL, SENIOR, STAFF
Source snapshot: Nov 12, 2026
View source