52 / 75
Medium
Remove Nth Node From End of List
#52linked-listtwo-pointers
Use two pointers with n-gap to find node before target, then skip target node.
Example:
Input:
head=[1,2,3,4,5], n=2Output:
[1,2,3,5] (removed 4)Common Mistakes:
- Not using dummy node (fails when removing head)
- Wrong gap size (should be n+1 to land before target)
- Trying to find length first (not one-pass solution)
- Off-by-one errors with pointer positioning
Notes:
Classic two-pointer technique. Time O(L) one pass, Space O(1). Dummy node simplifies edge cases.
💻
Java Solution Hidden
Enable “Show Full Solution” to view the code
Use two pointers with n-gap to find node before target, then skip target node.
Example:
Input:
head=[1,2,3,4,5], n=2Output:
[1,2,3,5] (removed 4)Common Mistakes:
- Not using dummy node (fails when removing head)
- Wrong gap size (should be n+1 to land before target)
- Trying to find length first (not one-pass solution)
- Off-by-one errors with pointer positioning
Notes:
Classic two-pointer technique. Time O(L) one pass, Space O(1). Dummy node simplifies edge cases.
52/75
Remove Nth Node From End of List