Run time error on test case -1 Please see the issue passing rest test cases.
Kth element from last in linked list - WA
You have stored your link list in the order:
1 2 3 4 5 6
/what is the 0th element from last? 1st element from last is 6./
if(k==0){
head->data; // seems incomplete
return;
}
/* there is a problem in this logic. It should display the first element not the last. The loop prior to it would execute n time(length of the link list) to satisfy this condition. This signifies that the value of k is n, which means you have to display the nth element from last i.e. the first element or element pointed by head. */
if(temp->next==NULL){
cout<data;
return;
}
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.