Data Structures & AlgorithmsHardTCS NQT · Accenture

A singly linked list holds 1, 2, 3, 4, 5, 6, 7. Adjacent pairs are swapped in one pass (node 1 with 2, node 3 with 4, and so on; an unpaired last node stays). What value is at position 4 of the result (1-based)?

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

Correct answer: D. 3

Swapping pairs gives 2 1 4 3 6 5 7, so position 4 holds 3. Swapping the data inside nodes versus relinking nodes gives the same values here.

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

Exams that ask this topic