Linked List Cycle
Problem
You are given the head of a singly linked list. Determine whether the list contains a cycle, meaning that following next pointers from the head eventually revisits a node instead of reaching None. Return true if a cycle exists and false otherwise. Aim for constant extra space.
- The list contains between 0 and 20,000 nodes.
- Node values fit in a signed 32-bit integer.
- Values may repeat, so you cannot detect a cycle by comparing values.
Examples
7 -> 11 -> 4 -> 9, and9points back to11→true. Followingnextfrom the head loops through11, 4, 9forever.2 -> 4 -> 6 -> 8, and8points toNone→false. The walk terminates.6withnext = None→false. A single node with no back-pointer is acyclic.
Hints
- Recording every visited node in a set works but costs O(n) memory. Can you detect "I have been here before" without remembering everything?
- Imagine two runners on a circular track at different speeds. Do they ever meet?
- Advance a slow pointer by one and a fast pointer by two. If the fast pointer reaches
None, there is no cycle; if it ever equals the slow pointer, there is.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.