K-append Problem

Sir I don’t find any way to optimise the code but it is stilll giving tle.Plzz help me in this code.

Hey @Alfred
did 2 corrections https://ide.codingblocks.com/s/411341
Now debug append function for
4
1 2 3 4
1

4
1 2 3 4
2

You did everything other than the changes i told lol

Do k=k%n before calling append function because k can be greater than n and in that case linked list make a whole rotation
say
1 2
and k=3
then we need to effectively place last 1 node head which is k%n=3%2==1

Also add a base case for k==0 i.e no rotation

https://ide.codingblocks.com/s/411378 Sir it is still showing one test case not passed

@Alfred
DO k%=n before checking for k==0

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.