Remove Nth Node From End of Linked List Java Program - The Coding Shala
Home >> Interview Questions >> Remove Nth node from the end of linked list
Remove Nth Node From End of Linked List
Given a linked list, remove the n-th node from the end of the list and return its head.
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5.
Remove Nth Node from the end of Linked List Java Program
We can remove the length-n+1 node. For this, we need to find out the length of the given linked list. To remove the nth node from the end of the list will take two passes.
We can do the same using two pointers. The fast pointer should be n place ahead from slow pointer and when the fast pointer reaches to the null remove the next node to slow pointer.
Other Posts You May Like