ProgrammingHard

Two pointers walk a linked list: fast goes two nodes per step, slow goes one. The list has an even number of nodes N = 8 and no cycle. After the loop while (fast && fast->next), how many steps has slow taken?

  1. A. 3
  2. B. 5
  3. C. 4
  4. D. 8

Correct answer: C. 4

Fast reaches the last node after 4 steps when N = 8. Slow has advanced one per step, so slow took 4 steps as well.

More C Programming questions

Exams that ask this topic