Please help me how to make correct my append function of my code for this question

Hello @kailash_01,

There are mainly two mistakes in the problem:

  1. To handle the case when k>=N:
    do K=K%N;
    This will, normalize the value of K to (0-N-1).
    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.

  2. For the case when k=N,2*N,… so on.
    just return from the function.
    Reason:
    The linked list should remain unchanged.

  3. In your code you have handled the links incorrectly.


Refer to the comments for better understanding.

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

what is difference between while(l–) and whle(–l)

Hello @kailash_01,

  1. Correction:
    //it should be n not len
    while(--n){
    temp=temp->next;
    }

  2. In while(n–), first it will check the value of n and then decrement it. While in while(–n), it will first decrement the value of n and then check it.

  3. Why am I using while(–n)?
    Because I want the loop to iterate for n-1 i.e. n-k-1 times.
    Using n-- will iterate it for n-k times.

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