Backlog·queued
Remove nth Node from End of List
DifficultyMedium
PatternTwo Pointers
TrackDSA
tl;dr
Given a singly linked list, remove the nth node from the end of the list and return its head.
full write-up
Constraints
- The number of nodes in the list is
k. - 1 ≤
k≤ 10³ - −10³ ≤
Node.value≤ 10³ - 1 ≤
n≤k
Examples
(Assuming this refers to a "Remove Nth Node From End of List" style problem — let me know if the actual problem differs and I'll adjust the examples.)
Example 1
Input:
head = [1, 2, 3, 4, 5]
n = 2
Output: [1, 2, 3, 5]
Example 2
Input:
head = [1]
n = 1
Output: []
Example 3
Input:
head = [1, 2]
n = 2
Output: [2]