Kth element from last in linked list NOT PASSING one testcase

my code is not passing one testcase i don’tknow where its wrong.
Here’s my code:

#include
#include
#include
#include
#include
#include
#define lli long long int
#define ll long int
using namespace std;
class node
{
public:
lli data;
node *next;
node(lli d)
{
data = d;
next = NULL;
}

};
void Insertathead(node *&head,lli data)
{
node * n = new node(data);
n->next = head;
head = n;
}
void print(node head)
{
node
temp = head;
while(temp!=NULL)
{
cout<data<<"->";
temp = temp->next;
}
}
node nTHnode(node&head,int k)
{
node * fast = head;

  node * slow = head->next;
  int i=1;
  while(fast->next!=NULL)  // as we don't want to implement last node since its next will be null
    {if(i<=k)
       {
        fast = fast->next;
       }
    else
     {
      fast = fast->next;
      slow = slow->next;
       }
     i++; 
    }
return slow;

}
void insertAtTail(node*&head,lli data){

if(head==NULL){
    head = new node(data);
    return;
}
node*tail = head;
while(tail->next!=NULL){
    tail = tail->next;
}
tail->next = new node(data);
return;

}
int main() {
node * head = NULL; //6,5,4,3,2,1
lli num;
scanf("%lld ",&num);

while(num!=-1)
  {
      insertAtTail(head,num);
      scanf("%lld ",&num);
  }

int k;
scanf("\n%d",&k);
node* ans = nTHnode(head,k);
cout<data;
return 0;
}
Please help, TIA!!