Linked list last nth element

how to proceed in this question . i don know which line is incorrect in my code . It is passing the sample test case but while submitting it shows wrong answer.

hello @rksrajneeshsah
Intuition

We notice that the problem could be simply reduced to another one : Remove the (L - n + 1) th node from the beginning in the list , where LL is the list length. This problem is easy to solve once we found list length LL.

Algorithm

First we will add an auxiliary “dummy” node, which points to the list head. The “dummy” node is used to simplify some corner cases such as a list with only one node, or removing the head of the list. On the first pass, we find the list length LL. Then we set a pointer to the dummy node and start to move it through the list till it comes to the (L−n) th node. We relink next pointer of the (L - n) th node to the(L−n+2) th node and we are done.

image

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.