Please tell me why this isn't working

Hello @sans_sehgal,

The logic you have applied seems wrong and complex.
You are required to do the following:

  1. first insert all the elements of linked list as insertAtTail() Method.
    2.Once, the linked list is build.
    …remove the node/element at last and
    node=last_node; //save that node in a temp variable (say node)
    second_last_node->next=NULL; //remove the last node
    …insert that element/node at head of the linked list.
    node->next=head;// insert last node at head
    head=node; //head pointing to new first node.
    …repeat the same for specified number of times(i.e. k).

Try to implement the above logic.
Hope, this would help.

@S18ML0016 hey no this doesn’t help. i dont wanna know what your logic is. i need you to tell me why my logic is wrong, i understand that it may be inefficient, but why is it not giving me the answer?

Okay, No problem.

The question says:
Append the last K elements of a linked list to the front.K can be greater than N.
Your code is producing failing for the following type of test cases, where k is greater than n.
8
1 2 2 1 8 5 6 1
10
Expected output:
6 1 1 2 2 1 8 5
Your Output:
1 2 2 1 8 5 6 1

Hope, this would help.
If you still face issues, let me know.

Do you want me to correct your code?

I have explained you one of your mistake.
If you have corrected that mistake and your code is still not passing testcases, then share the modified code.
I will help you.

As i explained earlier,
The following part of your code would not execute if k>x:
while(count<x-k)
{
head1=head1->next;
count+=1;
}

Which will result in no modification in the head1,
Hence, your code will print the same linked list.

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.