Pattern Studioalgorithmic thinking
All patterns

Fast & Slow Pointer

Linked Lists
Intermediate
Interactive

Move at two speeds until a cycle forces a meeting.

Time
O(n)
Space
O(1)
ActiveComparingMatch / bestIn windowFrontierVisitedExcludedAnswer
No frames to display.

The idea

Floyd's algorithm advances one pointer by one link and another by two. In a cyclic linked list, the faster pointer eventually laps the slower pointer, proving a cycle with constant extra space.

Analogy

A reusable way to think about organizing and navigating structured data efficiently.

When to reach for it

  • The relationships between values drive the algorithm.
  • You need efficient traversal, lookup, or updates.
  • An interview problem names or implies this structure.

Language-independent template

slow = fast = head
while fast and fast.next:
    slow = slow.next
    fast = fast.next.next
    if slow == fast: return true
return false

Complexity — time O(n), space O(1).

Common mistakes

  • Losing a pointer before saving its next target.
  • Breaking the structure invariant during an update.
  • Forgetting empty and single-node cases.

Practice progression

Canonical interview problems, ordered from foundation to advanced application.

Easy

Determine whether a linked list contains a cycle.

Medium

Find a repeated value without modifying the array or using extra space.

Hard

Reverse every complete group of k linked-list nodes.

Variations

Traversal
Insertion and deletion
Search and reconstruction