Jump to content
xisto Community

vivek.m

Members
  • Content Count

    2
  • Joined

  • Last visited

Posts posted by vivek.m


  1. But the answer that i expected is below..

    Just scan the list twice.

    You can get the kth element from the last.

     

    This algorithm is known as hare and tortoise algorithm.


    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.


  2. @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.  :)
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.