KTH NODE FROM LAST

I AM NOT ABLE HANDLE THE CORNER WHEN K IS EQUAL TO THE SIZE OF THE LL OR GREATER THAN LL
QUESTION–>
https://practice.geeksforgeeks.org/problems/nth-node-from-end-of-linked-list/1#
CODE–>

@sheikhhaji18 see my code
void printNthFromLast( struct Node *head, int n)

{

struct Node *main_ptr = head;

struct Node *ref_ptr = head;

int count = 0;

if (head != NULL)

{

while ( count < n )

{

if (ref_ptr == NULL)

{

printf ( "%d is greater than the no. of "

"nodes in list" , n);

return ;

}

ref_ptr = ref_ptr->next;

count++;

} /* End of while*/

if (ref_ptr == NULL)

{

head = head->next;

if (head != NULL)

printf ( "Node no. %d from last is %d " , n, main_ptr->data);

}

else

{

while (ref_ptr != NULL)

{

main_ptr = main_ptr->next;

ref_ptr = ref_ptr->next;

}

printf ( "Node no. %d from last is %d " , n, main_ptr->data);

}

}

}

I cannot understand what you did can u explain

i made a small mistake i found out https://ide.codingblocks.com/s/374891 just counting mistake

@sheikhhaji18 welldone! great happy coding.

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.