Amazon interview question

Write a program to fina a loop in a linked list

Interview Answer

Anonymous

15 Sept 2010

Have two pointers one is fast (2 steps at a time) and the other is slow (1 steps at a time). If at any moment fast == slow you have a cycle. Otherwise there is no cycle when fast hits the null.