Data Structures & AlgorithmsHardProduct-company MCQ pattern

Floyd's cycle detection runs on a linked list 1 → 2 → ... → 8 whose last node's next pointer points back to node 4 (0-based position 3). Slow moves one step, fast moves two steps per iteration until they meet. At what value do they first meet, and what value starts the cycle?

  1. A. meet 4, cycle start 4
  2. B. meet 6, cycle start 5
  3. C. meet 6, cycle start 4
  4. D. meet 7, cycle start 4

Correct answer: C. meet 6, cycle start 4

Simulating slow/fast pointer positions until they coincide gives the meeting node with value 6. Resetting one pointer to the head and advancing both one step at a time, they meet again exactly at the cycle's start, value 4 — this works because the head-to-start distance equals the meeting-point-to-start distance modulo the cycle length.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic