Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

A singly linked list holds 1..7. Using the slow/fast pointer method, the slow pointer reaches the middle node. How many nodes come after the middle node?

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

Correct answer: C. 3

For odd length the middle is the exact centre (node 4), leaving three nodes after it. The slow pointer stops at index 3 of 0-based indexing.

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

Exams that ask this topic