Intermediate
Data Structures & Algorithms
Q73 / 100
What is the key idea behind the "fast and slow pointer" (Floyd's cycle detection) technique on a linked list?
Correct! Well done.
Incorrect.
The correct answer is A) Two pointers move at different speeds; if the list has a cycle, the faster pointer will eventually meet the slower one inside the loop
A
Correct Answer
Two pointers move at different speeds; if the list has a cycle, the faster pointer will eventually meet the slower one inside the loop
Explanation
Floyd's algorithm advances a slow pointer by one node and a fast pointer by two nodes per step. If a cycle exists, the fast pointer laps the slow pointer and they meet inside the loop, detecting the cycle in O(n) time and O(1) space.
Progress
73/100