Kth element from last in linked list

what’s the problem in my code? It is not passing the third case.

Hey @yath17 the problem in this implementation is that you are not inserting the first element into linked list. So you’ll have to write insertAtEnd(head, num) before beginning while loop.
Let me know if you face any kind of problem in understanding the error.