Data Structures & AlgorithmsHardTCS NQT · Infosys

A queue has capacity 4 and an enqueue into a full queue is rejected. Operations in order: enqueue 1, 2, 3, 4; dequeue; dequeue; enqueue 5; enqueue 6; dequeue; enqueue 7. What is the front element of the queue afterwards?

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

Correct answer: D. 4

Track the contents explicitly: after the two dequeues only 3 and 4 remain, and the front changes each time a dequeue happens.

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

Exams that ask this topic