Recently I attended an interview and came accross the following question which I am not able to figure out.
Question-1:
As per the proof which I read Tortoise moves 1 step and Hare moves 2 steps at a time. I understood this and they will meet at some point since Hare moves twice the speed of Tortoise. Can't they have any random values like 2 and 3 or 3 and 5 or 2 and 4. If so, will they ever figure out the cycle? What is the condition for choosing the Tortoise and Hare values? Can we choose any random values?
Question-2:
Is there any condition for Tortoise and Hare to enter into the loop? Suppose if Tortoise and Hare have following values say 2 and 4 resp. And the linked list is like
3 / \ 1 - 2 4 \ / 5
If Tortoise enters in to loop at node 3 and Hare enters loop at node 2 then they both never meet each other inside the loop. So is there a condition for Tortoise and Hare to enter the loop?
Are there any confined values that should be choosen such that they meet each other?