Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A linked list is written as values 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8. The list is reversed in groups of 3 (the last group of fewer than 3 nodes is left as is). What is the value of the 4th node (1-indexed) afterwards?

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

Correct answer: A. 6

Reversing in groups of 3 gives 3 → 2 → 1 → 6 → 5 → 4 → 7 → 8, so the 4th node is 6. Reading 0-indexed position 4 gives 5, reversing in groups of 2 gives 2 → 1 → 4 → 3 (3), and the unreversed 4th node is 4.

More Coding Interview Problems questions

Exams that ask this topic