Skip to main contentSkip to solution

In which sequence the operations are allowed to result in a queue with:

XCV

Where the original array to be inserted was:

ZXCV

A. enqueue(Z)

B. dequeue()

C. enqueue(C)

D. enqueue(V)

E. enqueue(X)

Solution

✅ Correct Option: 1

A queue is FIFO (first in, first out): items are added at the rear and removed from the front. The original order Z, X, C, V must be enqueued in that order, and the one dequeue must remove Z from the front.

Enqueueing Z, X, C, V (A, E, C, D) gives Z, X, C, V, and then dequeue() (B) removes Z, leaving X, C, V.


Option 2: dequeue() runs right after enqueue(Z), so Z is removed immediately. The remaining enqueues give V, C, X, which is the wrong order.

Option 3: dequeue() is called on an empty queue, which is underflow.

Option 4: enqueue(C) then dequeue() removes C, not Z. The final queue is V, Z, X.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question