1.

How To Find The Kith Node From The End In A Singly Linked List?

Answer»
  • This is one of the tricky but frequently asked linked list QUESTIONS. Some of you may be wondering how do you find kth node from end, singly linked list can only TRAVERSE in one direction and that is forward then how do you count nodes from the end.
  • Well, you don't have to, you can still move forward and count nodes from the end? Actually, that's the trick. You can use two pointers to find the Nth node from the end in a singly linked list. They are known as fast and slow points.
  • You start slow POINTER when the fast pointer reaches to the Kth node from start e.g. if you have to find 3rdnode from the end then you start slow pointer when the fast pointer reaches to the 3RD node. This WAY, when your fast pointer reaches to the end, your slow pointer will be on the 3rd node from the end.



Discussion

No Comment Found