All Patterns
🐇🐢
mediumPattern #03

Fast & Slow Pointers

Floyd's cycle detection — two pointers at different speeds.

What is this pattern?

Also called Floyd's Tortoise and Hare. One pointer moves one step at a time (slow) and another moves two steps (fast). If they meet, there is a cycle. Where they meet encodes cycle properties — position, length, or a duplicate value.

When to use it

  • Detecting a cycle in a linked list or sequence
  • Finding the start of a cycle
  • Finding the middle of a linked list
  • Detecting a duplicate without extra space

Key Insight

When fast and slow meet inside a cycle, reset slow to head. Moving both one step at a time from there brings them to the cycle entrance — a mathematical property of the meeting point.

Pro Content

The Java template and practice problems for this pattern are part of the Pro plan. Upgrade to unlock all patterns, 500+ problems, and Aria code reviews.

View pricing

From ₹3,999 for a year · one-time, no auto-renewal