Pick the fix
Inside a loop, the fast pointer is 3 links behind the slow one. How many steps until they meet?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 3
Right: the gap shrinks by one per step.
Because the gap closes one link at a time, the meeting happens within one lap, which keeps the whole check linear.
Why not the others?
- B 6. Only the difference in speed matters, and that is one link per step.
- C It might never meet. A gap that drops by one each step must reach zero.
Steps come from running the Python solution.
Text version
Tail joins link 2:
Links [3, 8, 1, 6, 4]; the last link points back to link 2.
- slow = 1, fast = 2. Slow at 8, fast at 1
- slow = 2, fast = 4. Slow at 1, fast at 4
- slow = 3, fast = 3. Slow at 6, fast at 6: they meet, so there is a loop
Result: true
No loop:
Links [3, 8, 1, 6].
- slow = 1, fast = 2. Slow at 8, fast at 1
- slow = 2, fast = end. Slow at 1, fast at end
- slow = 2, fast = end. Fast reached the end: no loop
Result: false