GATE Computer ScienceModerateGATE CS (PYQ pattern)

A singly linked list 1 -> 2 -> ... -> 12 is modified by reversing the sublist from position 3 to position 9 (1-indexed, inclusive), and then reversing the sublist from position 5 to position 11 of the resulting list. What is the list now?

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

Correct answer: C. 1 2 9 8 11 10 3 4 5 6 7 12

After the first reversal the list is 1 2 9 8 7 6 5 4 3 10 11 12; reversing positions 5 to 11 of that gives 1 2 9 8 11 10 3 4 5 6 7 12.

More Programming and Data Structures (GATE) questions

Exams that ask this topic