Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2

A singly linked list has a tail of 4 nodes leading into a cycle of 6 nodes. Floyd's method moves a slow pointer 1 step and a fast pointer 2 steps in each round, starting both at the head. After how many rounds do they first meet?

  1. A. 4
  2. B. 10
  3. C. 12
  4. D. 6

Correct answer: D. 6

After i rounds the slow pointer is at position i and the fast one at 2i. They first coincide when i is at least the tail length 4 and divisible by the cycle length 6, so i = 6.

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

Exams that ask this topic