TEST CASES SHOWING WRONG.GIVING RIGHT OUTPUT ON VSCODE

#include
using namespace std;

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

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

};

node *head=NULL;

void find()
{
node *slow=head;
node *fast=head->next;

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

}

void Create()
{
int n;
cin>>n;
head=new node(n);
node *t=NULL;
node *tail=head;

while(n!=-1)
{
	cin>>n;
	t=new node(n);
	tail->next=t;
    tail=t;
    
}	

}

int main()
{
Create();
find();
}

Hey, which ques are u referring to?

Given a linked list with n nodes. Find the kth element from last without computing the length of the linked list. Input Format First line contains space separated integers representing the node values of the linked list. The list ends when the input comes as ‘-1’. The next line contains a single integer k.

Hey, refer this-https://ide.codingblocks.com/s/646228?_ga=2.71504922.869129830.1652372690-62531247.1625483271

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.