Skip to content
Preptima
mediumCodingEntryMidSenior

Detect whether a linked list has a cycle, and return the node where the cycle begins.

4 min readUpdated 2026-08-15

Answer

Short answer

Advance one pointer by one node and another by two; if they ever coincide there is a cycle. Then reset one pointer to the head and step both one node at a time, and they meet at the cycle's entry.

Was this answer helpful?

Likely follow-ups

  • How would you compute the length of the cycle once you have detected it?
  • Why does a step ratio of one and two guarantee a meeting, and would three and one still work?
  • How would you find the middle node of a list in one pass with the same technique?
  • Reverse the list iteratively and tell me which pointer you return.

Related questions

Related Topics