Kth node from end- I am stuck here

node* k_end(node*&node,int k)
{
nodefirst=head;
node
second=head;
int cnt=0;
while ( cnt < k)
{
first=first->next;
cnt++;
}

}

Hey @vashishthkuntal.gajjar2019 share your code using ide.codingblocks.com i’ll let you know your mistake.

See this diagram


First increment f to k steps represented by yellow, after that increment both f and s until you see f-> next equal to Null when you hit it, return s which is last kth node.

Check now =>

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.