Category Archives: Linked List

Kth node from last of linked list

Print Kth node from last of linked list.

Algorithm:
  1. If node is null then
    1. return 0
  2. Recursively call same method with node.next
  3. After call increment node counter
  4. If node counter == k then
    1. Print node
  5. return node counter

Latest Source Code:
Github: KthNodeFromLast.java


Output:

 1 2 3 4 5 
The 1th Node is :5
The 2th Node is :4
The 3th Node is :3