Kth node from the end of linked list

node* kelement(node* head,int k)
{
if(head==NULL || head->next==NULL)
return head;
int i=1;
node* fast=head;
node* slow=head;
while(i<=k)
{
fast=fast->next;

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

}

For calculating kth node from end of linked list,what is wrong in this function?

hello @shubhangis248
please share ur complete code using cb ide

check now->

giving segmentation fault for input- 1 2 3 4 5 6 7 -1 and key=3

added i++ in line 68

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.