What goes in the blank?
# Floyd cycle detection on a linked list
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.____
if slow is fast:
return True
return False
Answer: next
The fast pointer moves two nodes per step; inside a cycle it must eventually land on the slow one.
Play Problem Solving ▸