How to determine whether a linked list contains a loop?

Posted by ET on Stack Overflow See other posts from Stack Overflow or by ET
Published on 2010-06-08T22:13:42Z Indexed on 2010/06/08 22:22 UTC
Read the original article Hit count: 170

Filed under:

During a preparation for a job interview, I encountered the following question:

How can you determine whether a linked list (of any type) contains a loop, using additional space complexity of O(1)? You cannot assume that the loop starts at the first node (and of course, the loop doesn't have to contain all nodes).

I couldn't find the answer, though I have the feeling it's quite simple...

© Stack Overflow or respective owner

Related posts about linked-list