← Pointer Manipulation

Micro-Drill #25 — Find middle (slow/fast)

Pointer Manipulation Target: 10s

Fast/slow pointer finds the middle in one pass. Core technique for merge sort on lists.

slow, fast = head, head
while fast and fast.next:
    slow = slow.next
    fast = fast.next.next
# slow is at the middle

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #24 Micro #26 →