Print Kth node from last of linked list.
Algorithm:
- If node is null then
- return 0
- Recursively call same method with node.next
- After call increment node counter
- If node counter == k then
- Print node
- 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