how to Find Duplicate Number in an array

Опубликовано: 26 Июль 2026
на канале: kuda the Coder
17
4

Using a slow and a fast pointer to find a duplicates number in an array.

Cycle Detection (Step 1):
Use two pointers (slow and fast):
slow moves one step at a time.
fast moves two steps at a time.
When slow equals fast, a cycle is detected.


2. Find the Duplicate (Step 2):
Reset slow to the start of the array.
Move both slow and fast one step at a time.
The point where they meet is the duplicate.