Linked list K appendq

i believe my code is correct but still two test cases did not pass.

Hi Neerav,
Your code looks fine to me, but there is just one end condition which is the reason you are failing those conditions.

Think of a situation where number of elements are less than “K” elements.
It means K is greater than the number of elements in the array.
Just add this condition & you are good to go.

If you have any other doubts, please feel free to ask.

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.

on line number 97 I have included that condition already but it is still not working

No, if you have 5 elements & k=6;
add this condition in your code.

@WARHEAD
Try this testcase.
Input :
10
1 2 3 4 5 6 7 8 9 10
13

Expected Output :
8 9 10 1 2 3 4 5 6 7

Your Output :
1 2 3 4 5 6 7 8 9 10

1 Like