Data Structures & AlgorithmsVery hard

A linked list has nodes numbered 0 to 9 in order, and node 9's next pointer returns to node 3. Two pointers start at node 0: slow moves one node per step and fast moves two. At which node number do they first meet?

  1. A. 3
  2. B. 9
  3. C. 7
  4. D. 8

Correct answer: C. 7

Once both pointers are in the loop (nodes 3 to 9, a cycle of length 7), fast gains one node per step on slow, so they meet after a bounded number of steps at a node inside the cycle. The loop entry node 3 is the start of the cycle, not the meeting point here.

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

Exams that ask this topic