Data Structures & AlgorithmsHardInfosys DSE · Cognizant GenC Elevate

A singly linked list holds 1 to 10 in order. Every block of k = 4 consecutive nodes is reversed in place, but a final block with fewer than 4 nodes is left as it is. What is the resulting order?

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

Correct answer: A. 4 3 2 1 8 7 6 5 9 10

Blocks 1-4 and 5-8 are full and get reversed, giving 4 3 2 1 8 7 6 5. The leftover 9 10 has only two nodes, so it stays unchanged; reversing it is the common slip.

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

Exams that ask this topic