Kth element from last in LL

I am facing run-error in one of the test cases.
Please look into the code.

6 5 4 3 2 1 -1
6

check ur code for above test case

the o/p generated by the code is 5 but it should be 6