Microsoft Interview Question

how do you find the loop in a linked list

Interview Answers

Anonymous

Jul 31, 2011

Think "The Tortoise and the Hare" - walk the list with 2 pointers: 1st pointer moves slow (+ 1 node); 2nd moves fast (+2 nodes); If the 2nd pointer ever 'catches up' to the 1st pointer then there's a loop.

3

Anonymous

Jul 27, 2011

ran out of time