vivek.m
-
Content Count
2 -
Joined
-
Last visited
Posts posted by vivek.m
-
-
@sanjay0828Good one... the expected solution.
Again... i want a simpler solution. What will be the basic answer that comes to your mind if i give this problem.??
Very basic.. ..
If no answer i will be posting it in my next post.
the most basic and the only answer that came to my mind (actually, my frnd's mind. I am too laazy to use mine) is to find length and then to find the (l-n)th element with o(n2) complexity.
i am interested in your answer.. it's more than a month since you posted your question.
Data Structures -- Linked List Find the nth last element in linked list.
in Programming
Posted · Edited by vivek.m (see edit history) · Report reply
That's same as what I said... In first scan, find the length and in second scan, find the required element. This seems to be only tortoise-tortoise scan.
The other answer (your and sanjay's answer) is more efficient with worst case operations half of what is required in first answer. complexity will be o(n) in both cases. (my bad. i had to edit. i mentioned complexity o(n^2) incorrectly.)
Thanks for the problem.