Each test case erroe

#include
using namespace std;
class node{

public:
	int data;
	node *next;
	
node(int value){
	data=value;
	next=NULL;
}

};

void Inserthead(node *& head,int value){
if(head==NULL){
head=new node(value);
return;
}
node n=new node(value);
n->next=head;
head=n;
}
void insertAt_tail(node
&head,int value){
if(head==NULL){
head= new node(value);
return;
}
node n=new node(value);
node
temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
}
void print(node head){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
}
node * input_func(){
int d;
cin>>d;
node
head=NULL;
while(d!=-1){
insertAt_tail(head,d);
cin>>d;
}
return head;
}

int kth_element(node* head,int key){
node * slow=head;
node * fast=head;
int count=1;
while(count<=3){
fast=fast->next;
count++;
}
while(fast!=NULL){
slow=slow->next;
fast=fast->next;
}

return slow->data;
}

int main(){
node * head=input_func();
int n;
cin>>n;
cout<<kth_element(head,n);
cout<<endl;

return 0;

}

hi @kumawatnitesh093
count<=key not count<=3

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.