Linked List - k - append problem

what’s the error in code only two test caes are passing----https://ide.geeksforgeeks.org/AsmBSZgwMv

@AbhishekAhlawat1102,

incase n>N, your code will give error.

Input:
7
1 2 2 1 8 5 6
7
your Output:
Error

Input:
7
1 2 2 1 8 5 6
8
Your output:
Error

ok now three test cases are passing but not all now what are errors in this new code----https://ide.geeksforgeeks.org/7gwkxa1wP3

@AbhishekAhlawat1102,
https://ide.codingblocks.com/s/253776 corrected code.

I have commented the lines where there was error.

Also add n= n%N; to your code.

though its given that n>N is a possible input who do we came to know that for n>N, we should use n%N

@AbhishekAhlawat1102,
Because
7
1 2 3 4 5 6 7
8
is same as
7
1 2 3 4 5 6 7
1

if n>N, you are just appending all the elements n/N times. Hence you just need to take care of the remainder which is n%N

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.