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.
![Animated sliding window over the array [2, 1, 5, 1, 3, 2]: a three-number window adds the new number and subtracts the old one, showing sums 8, 7, 9 and 6 and a maximum of 9.](https://i.ytimg.com/vi/NM5paB6_7wg/maxresdefault.jpg)

![Animated Two Sum walkthrough on the array [3, 8, 4, 6, 1] with target 10: each number asks what it needs, a dictionary stores the numbers already seen, and 6 finds 4, returning indices [2, 3].](https://i.ytimg.com/vi/Fa-tiOP33hY/maxresdefault.jpg)