Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

​

Introduction to Fast & Slow Pointers Pattern

The Fast & Slow pointer approach, also known as the Hare & Tortoise algorithm, is a pointer algorithm that uses two pointers which move through the array (or sequence/LinkedList) at different speeds. This approach is quite useful when dealing with cyclic LinkedLists or arrays.

By moving at different speeds (say, in a cyclic LinkedList), the algorithm proves that the two pointers are bound to meet. The fast pointer should catch the slow pointer once both the pointers are in a cyclic loop.

One of the famous problems solved using this technique was Finding a cycle in a LinkedList

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 3 years ago

What kind of introduction to pattern is this? No theory at all; only tasks There is no feeling of gradual progress when you first don't teach and then just explain how I'm supposed to do it.

A

Anonymous

· 4 years ago

I would also recommend https://leetcode.com/problems/find-the-duplicate-number/ as good problem to practice Fast and Slow pointers (Floyd's cycle detection) since its not listed in this section

Reading Progress

0%


Vote for new content