Data Structures & AlgorithmsVery hardTCS NQT · Accenture

Apply the reversal of the first 4 elements to the queue 1, 2, 3, 4, 5, 6, 7, 8 (front first). What is the element at position 6 of the resulting queue (1-based)?

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

Correct answer: A. 6

Reversing the first 4 gives 4, 3, 2, 1, 5, 6, 7, 8; the reversal uses a stack for the first k elements and then re-enqueues the rest in order.

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

Exams that ask this topic