Program for find n’th node from the end of a Linked List

Question : Given a Linked List and a number n, write a program  that find the value at the n’th node from end of the Linked List.

Method 1 – Use length of linked list

1.   Calculate the length of Linked List. Follow this tutorial Find Length of a Linked List data

2.   Print the (len – n + 1)th node from the beginning of the Linked List.

Code in Java

Output :

Given Linked list : -> 4-> 2-> 7-> 9-> 1
nth node in list from end is 9

Time Complexity: O(n) where n is the length of linked list.

Here is more LinkedList interview questions :

  1. Reverse a Linked list data structure in java

  2. Find the middle of a given linked list data structure
  3. Inserting a new node in a linked list data structure
  4. Find Length of a Linked List data structure (Iterative and Recursive)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.