Simple question on linked list(Hare and tortoise) like find mid or find the loop and remove the loop? And write the code.
Sigiloso
Run one node at rate(slow) 1 node per iteration and another(fast) 2 node till we hit 2nd pointing to null. then return slower node. Same for loop, if we find that slow==fast then there is loop. now fix one node and move another at speed 1 node per iteration(slow = slow.next). and keep count of the nodes that we have traversed till we hit fast again. That is the number of nodes in the circle(k). now from start from head and keep another node at distance k now go 1 node each iteration, the point where they meet is the starting point make the last.next=null. He also asked if we make the fast = fast.next.next.next will they ever meet? I gave him a general answer that in a circle if one is running at even slight higher speed than another the faster will again catch the slower every single time.