FreeCareerPath
Build the PrimitiveEasy

Linked List Cycle

Write `has_cycle(head)` returning `True` when the list contains a cycle. A set of visited nodes works and costs O(n) memory. The expected answer is Floyd: a slow pointer moving one step and a fast one moving two. Inside a cycle the fast pointer gains exactly one position per iteration on the slow one, so it cannot step over it — that argument is the follow-up.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Linked List Cycle" are saved to your account — logging in takes a few seconds.