Detect a cycle in a linked list

Which technique detects a cycle in a linked list in O(1)O(1) extra space?

Show hints (2)+
  1. The constraint is O(1)O(1) space, so a hash set is out.
  2. Two pointers at different speeds will coincide inside a loop.

Answer

Reveal answer →

Floyd's fast/slow (tortoise-and-hare) pointers - O(1)O(1) space

Create a free account to see the full worked solution and track your progress.

Interview format: Hedge Fund Quant, Options Trading

Related questions