Code shows run error in most of the test cases

hello, I tried to use slow and fast pointer approach as we can get both the end of the ll and the point from where to break from but it throws run error

Hello @gurkirat2600,

Note that K can be greater than N.
Your code is not working when k>N, to remove the error you simple need to do k %= N;
You will observe that after n nodes are appended in the front then, the linked list comes back to the original position. So, simply subtract n from the k until k is less than n (means k %= N).

thank you, sir for solving the doubt

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.