Data Structures & AlgorithmsVery hardGATE CS

A singly linked list holds 1, 2, ..., 11 in order. Starting from the head, every alternate group of k = 3 consecutive nodes is reversed in place (the 1st, 3rd and 5th groups are reversed; the 2nd and 4th are left as they are; the last group has fewer than 3 nodes). What is the value stored in the 9th node of the resulting list?

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

Correct answer: A. 7

Groups: (1,2,3) reversed, (4,5,6) kept, (7,8,9) reversed, (10,11) is the 4th group and is kept, giving [3, 2, 1, 4, 5, 6, 9, 8, 7, 10, 11]. Hence the 9th node holds 7.

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

Exams that ask this topic