Detect a Cycle (Floyd's Algorithm)

Easy · Linked Lists · about 10 minutes

Asked at Amazon, Microsoft, Bloomberg, Apple.

Decide whether following the next pointers from head ever leads back to a node you've already passed, i.e. whether the list loops. Use O(1) extra memory.

Related guides