In "Linked List-K Append" question, My code is not able to pass 2nd,3rd and 5th test case, please tell me what is the mistake in my code or tell the solution

#include

using namespace std;

class node
{
public:
int data;
node* next;

node(int d)
{
    data=d;
    next=NULL;
}

};
node* head=NULL;
void change(node* head,int k)
{
int count=0;
if (head->next==NULL)
{
cout<data<<" “;
return ;
}
node* temp=head;
node* prev=head;
node* curr=head;
node* naya;
while(temp)
{
count++;
temp=temp->next;
}
for (int i=0;i<count-k;i++)
{
prev=curr;
curr=curr->next;
}
naya=prev->next;
prev->next=NULL;
while(curr->next)
{
curr=curr->next;
}
curr->next=head;
while(naya)
{
cout<data<<” “;
naya=naya->next;
}
}
void kth(node* tempo, int k)
{
node* fast=tempo;
node* slow=tempo;
while(k–>0 && fast)
{
fast=fast->next;
}
while(fast)
{
fast=fast->next;
slow=slow->next;
}
cout<data;
}
int main()
{
node* temp;
int a,x,aa;
cin>>a;
aa=a;
while(aa–)
{
cin>>x;
if (head==NULL)
{
head=new node(x);
temp=head;
}
else
{
temp->next=new node(x);
temp=temp->next;
}
}
int k;
cin>>k;
if (k>=a)
{
while(head)
{
cout<data<<” ";
head=head->next;
}
return 0;
}
node* h=head;
cout<<endl;
change(head,k);

return 0;
}

hello @goyalyash1962

pls save ur code at cb ide and share its link with me

chekc now->

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.