The program to find the nth node from the end of a linked list is discussed here. Given a linked list, the task is to find the Nth node from the end of the list and return it.
This problem can be solved in two different ways.
Method 1: By finding the length of the linked list, the Nth node from the end can be found easily.
Method 2: By using two pointers, the Nth node from the end can be found.
For example, consider the linked list given below.
Linked List : 1 -> 2 -> 3 -> 4 -> 5
4th node from the end is 2
@@coding::1@@
Time complexity: O(n)
@@coding::2@@
Recommended Programs