← Pointer Manipulation

Micro-Drill #271 — Floyd's cycle detection (find start)

Pointer Manipulation Target: 15s

Phase 1: detect cycle with slow/fast. Phase 2: reset slow to head, advance both by 1 — they meet at cycle start.

slow = fast = head
while fast and fast.next:
    slow = slow.next
    fast = fast.next.next
    if slow == fast:
        slow = head
        while slow != fast:
            slow = slow.next
            fast = fast.next
        return slow  # cycle start

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #270 Micro #272 →