So the question is: find kth node frm last in the linked list if nodes a disappearing once read . This should be done in one go.
Try to avoid extra memory.
I am aware of a trivial solution to this problem, where two pointers (P and Q) are taken into the node header, and P increases them N times, and after that both pointers increase. Pointer Q points to the last element of N.
But the question here is somewhat different: where the nodes disappear after reading them, so you cannot use two pointer methods.
And do not kindly close the question before reading it. because this question is different.
thanks
source share