I am getting wrong answer

my linked list is not appended and instead it give me the same output as the input

error is due to your
build list function
it takes more than n inputs and hence k get garbage
so k<n hence you return head in function

  1. 2nd mistake
    when k==n return head;
    when k>n you have to set k=k%n;

Modified Code

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.