k_append-LInkedList


i m getting TLE
plz hepl me out with the code

Your code is not producing any output, thus I would recommend you to either return newHead from the append function, since the output is not produced.

but i have done cout ?shdnt it work?

after passing k_append by refernce?
@yuktimutreja01


it is still giving TLE

plz help me out with the code

Eshanika, plz change your append function and use the below logic or approach of slow and fast headers in your code for the same,

node *append_nodes(node *head,int k)
{
node *slow=head;
node *fast=head;
node *oldhead=head;
for(int i=0;i<k && fast->next!=NULL;i++)
{
fast=fast->next;
}
while(fast->next!=NULL && fast!=NULL)
{
fast=fast->next;
slow=slow->next;
}
node *newHead=slow->next;
slow->next=NULL;
fast->next=oldhead;
return newHead;
}