Data Structures & AlgorithmsHardTCS NQT · Accenture

Two queues hold [1, 3, 5] and [2, 4, 6]. The output takes one element from the first queue, then one from the second, alternately, until both are empty. What is the value at position 4 of the output (1-based)?

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

Correct answer: D. 4

Interleaving the queues gives 1, 2, 3, 4, 5, 6, so position 4 (1-based) holds 4. Reading the position as a 0-based index gives 5, the most tempting slip; 6 is the last element and 8 is in neither queue.

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

Exams that ask this topic