ProgrammingVery hardWipro · TCS NQT pattern

What is the final content of the queue (front to back, left to right) after this sequence of operations on an initially empty queue?

What is the final content of the queue (front to back, left to right) after this sequence of operations on an initially empty queue?
enqueue 98
dequeue
enqueue 87
enqueue 95
dequeue
enqueue 66
enqueue 82
enqueue 57
enqueue 33
dequeue
  1. A. 95, 66, 82, 57, 33
  2. B. 33, 57, 82, 66
  3. C. 87, 66, 82, 57
  4. D. 66, 82, 57, 33

Correct answer: D. 66, 82, 57, 33

A queue is FIFO: dequeue always removes the front (oldest) element. Tracing the sequence gives front-to-back [66, 82, 57, 33]. Treating it like a stack (removing the most recent instead) gives the trap [87, 66, 82, 57]; reading it back-to-front gives [33, 57, 82, 66].

More Pseudocode and Code Tracing questions

Exams that ask this topic