Can you tell why it is not passing test cases

#include
using namespace std;

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

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

};

void insertAtHead(node*&head,int data){
node* n=new node(data);
n->next=head;
head=n;
}

void display(node* head){
node* temp=head;

while(temp!=NULL){
    cout<<temp->data<<" ";
    temp=temp->next;
}
cout<<endl;

}

void insertAtTail(node* &head,int data){
if(head==NULL){
insertAtHead(head,data);
return;
}

node* tail = head;

while(tail->next!=NULL){
    tail = tail->next;
}

node* n= new node(data);
tail->next = n;

}

node* findMid(node* head){

node* fast=head;
node* slow=head;

while(fast!=NULL && fast->next!=NULL){
    slow=slow->next;
    fast=fast->next->next;
}

return slow;

}

node* merge(node* &a, node* &b){

if(a==NULL){
    return b;
}

if(b==NULL){
    return a;
}

node* c;

if(a->data <= b->data){
    c=a;
    c->next=merge(a->next, b);
}
else{
    c=b;
    c->next=merge(a, b->next);
}

return c;

}

int main()
{
int t;
cin>>t;
while(t–){
int n1;
cin>>n1;
node* head1=NULL;
while(n1–)
{
int data;
cin>>data;
insertAtTail(head1,data);
}
int n2;
cin>>n2;
node* head2=NULL;
while(n2–)
{
int data;
cin>>data;
insertAtTail(head2,data);
}
//display(head);

node* h=merge(head1,head2);
display(h);
return 0;
}

}

Hi @mvarun975_a7021058d653891d, if u r getting tle or mle then do insertion in o(1) u r doing insertion in o(n)

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.