LeetCode pattern lab · O(1) space

Fast meets Slow.The structure reveals itself.

Watch two traversal speeds expose a midpoint, prove a cycle, and locate a duplicate inside an implicit graph. Every fast move remains two visible hops.

Current mission

Middle of the Linked List

Easy
Steps8
Checkpoints4
SpaceO(1)

Problem deck

Choose the chase

Playback console

Control the motion

1 / 8
Choose a problem, inspect the structure, then launch the chase.

Structural linked layout

Find the midpoint

Both pointers begin at the head. Slow moves once per round; Fast moves twice.

Round0
Slow moves0
Fast moves0
1index 0
2index 1
3index 2
4index 3
5index 4
6index 5
SLOW ↓
FAST ↓
null
Slow · one hopFast · two hopsMeeting / answerCycle entrance

Live decision inspector

Why does it move?

Ready

Why use two different speeds?

slow += 1 hop · fast += 2 hops

Next action

Check whether Fast can safely move twice

When Fast covers the entire list, Slow covers half of it.

Invariant

After each complete round, Fast has travelled twice as many edges as Slow.

Execution trace

Code in motion

def middleNode(head):
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
return slow

Why does this work?

Proof laboratory

Reveal the distance argument after you can predict the pointer movement yourself.

Local mastery

Your pattern record

Middle of the Linked List0 runs0%
Linked List Cycle0 runs0%
Find the Duplicate Number0 runs0%

Completion, proof exploration, and best prediction accuracy stay in this browser.

Run in progress

The answer is still moving.

Complete the chase to record this problem. Prediction mastery requires at least 70% accuracy.

Recognize the pattern

When should you use Fast & Slow Pointers?

Look for a sequence of states where each state determines exactly one next state. If the sequence can terminate, Fast may reach null. If a state can repeat, different traversal speeds can expose the cycle without a visited set.

Is there a deterministic next state?
Can a state repeat or form a cycle?
Do I need O(1) extra space?
Can speed reveal a midpoint or entrance?

Common mistakes

  • Checking for a collision before the pointers make their first move.
  • Moving Fast twice without guarding both hops against null.
  • Treating Find the Duplicate Number as value comparison instead of state traversal.
  • Resetting both pointers before Phase 2 instead of only one.
O(n) timeO(1) spaceNo mutation