Alexander Obregon's Substack

Share this post

User's avatar
Alexander Obregon's Substack
LeetCode #19: Remove Nth Node From End of List
Java LeetCode Solutions

LeetCode #19: Remove Nth Node From End of List

Two-Pass Length Then Delete and One Pass Two Pointers

Alexander Obregon's avatar
Alexander Obregon
Aug 13, 2025
∙ Paid
1

Share this post

User's avatar
Alexander Obregon's Substack
LeetCode #19: Remove Nth Node From End of List
Share
LeetCode Logo
Image Source

This LeetCode problem involves taking out a node from a singly linked list based on its position counted from the end. The input gives the head of the list and a number that tells you which node from the end needs to be removed. The output is the same list without that node, with all remaining nodes left in their original order. The challenge is that a singly linked list only moves in one direction, so finding the target node from the end requires some planning before making any changes.

Thinking through a solution starts with figuring out how to reach the node to be removed while still keeping track of the list’s structure. One method is to pass through the list to measure its length, then pass through again to stop just before the target node. Another method is to use two pointers that move at different times so you can locate the target in a single trip. Each method has its strengths, and knowing both gives more flexibility when deciding which to use.

LeetCode: Remove Nth Node From End of List

Given the head of a linked list, remove the nth node from the end of the list and return its head.

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 = 1
Output: [1]

Constraints:

  • The number of nodes in the list is sz.

  • 1 <= sz <= 30

  • 0 <= Node.val <= 100

  • 1 <= n <= sz

Keep reading with a 7-day free trial

Subscribe to Alexander Obregon's Substack to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Alexander Obregon
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share