Why this one's not working?

Why this one’s not working?

Hello @cbcao263,

Mistakes in your code:

  1. Segmentation Fault:
    Line number 23 which is causing invalid memory access.

  2. No output:
    Missing call for printt function.

  3. Wrong Output:
    You have missed an important part of the question:
    Note that K can be greater than N.
    So, your code is failing for k=>N
    Example:
    7
    1 2 2 1 8 5 6
    8
    Expected Output:
    6 1 2 2 1 8 5
    Your Output:
    1 2 2 1 8 5 6

Observation:
The required output is the same as that of k=1.
Similarly,
for k=7 the output is the same as that of k=0.
for k=9 the output is the same as that of k=2.

Solution:
k = k mod n;
this would limit the value of k within the range [0,n-1]
Check line 65.

Also, if k=0 or k= multiple of n then the linked list will be same.

Corrected Code:

Hope, this would help.
Give a like, if you are satisfied.

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.