Run error linked list k asppend

Hello @S19LPPP0132,

You are facing error due to the following code for value of k=>n:
while(count!=length(head)-index){
temp = temp->next;
count++;
}

Dry run this part for n=7 and k=7, you would understand the logical error your code is facing.

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

1 Like

I am not able to figure out the logic for index=>n
please help me with the answer .

What you can do:

  1. remove last element and then insert at head.
  2. Repeat this k times.

While doing this keep track of second last element.
second_last->next=NULL

Hope, this would help.

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.