This practice workspace is built for desktop. Open it on a larger screen to start solving.
Remove Nth Node From End of List
Given the head of a linked list, remove the n-th node from the end of the list and return the head of the modified list.
Input/output convention for this exercise: the list is passed as an array of values; return the modified list as an array of values. The starter provides ListNode, arrayToList, and listToArray — convert to a real list, do the removal, then convert back.
The classic one-pass solution uses two pointers separated by n steps: advance the lead pointer n nodes ahead, then move both together until the lead reaches the end. The trailing pointer now sits just before the node to remove. A dummy head node simplifies removing the first node.
Examples
Constraints
- 1 <= values.length <= 30
- 0 <= values[i] <= 100
- 1 <= n <= values.length
Preview Mode
This is a read-only preview of DSAMind's AI coaching. Sign up to get custom feedback on your own solution.
Your approach
- Pattern:Linked List
- Time:O(N)
- Space:O(1)
Complete approach — pattern and complexity both named.
Coach
What you got right
You correctly matched the sorted input requirement and implemented a linear-time scan using two pointers.
Where it diverged
No divergence detected. The code correctly aligns with the stated approach.
Next attempt: focus on
Try solving related sliding window problems to build familiarity with two-pointer variants.
Signals
No signals fired — clean run, you stayed in flow.