Skip to content
Interview

Interview

Find the Duplicate Number in O(1) Memory: Floyd's Tortoise and Hare, Animated

· Find the duplicate number, O(1) memory | Tortoise and hare trick

Find the duplicate without changing the array or using extra memory. Treat each number as a slip naming the next locker: a loop forms, and the duplicate is its door. Floyd's tortoise and hare finds it in O(n) time, O(1) memory.

Interview SheetFind the Duplicate Number, explained in fullThe idea, the steps, the complexity and the code in four languages, plus the rest of the Fast and Slow Pointers pattern.