Skip to main contentSkip to solution

Consider an empty queue and the order of given elements fom left to right.

[35, 55, 15, 62, 43, 24]

What will be the front element of the queue list after following operations are performed?

  1. ENQUEUE
  2. ENQUEUE
  3. PEEK
  4. DEQUEUE
  5. ENQUEUE
  6. DEQUEUE
  7. DEQUEUE
  8. ENQUEUE

Solution

✅ Correct Option: 2

A queue is first in, first out: ENQUEUE adds the next element from the list at the rear, DEQUEUE removes the front element, and PEEK only reads the front without removing it.

OperationQueue (front on left)
1. ENQUEUE 3535
2. ENQUEUE 5535, 55
3. PEEK (returns 35)35, 55
4. DEQUEUE (removes 35)55
5. ENQUEUE 1555, 15
6. DEQUEUE (removes 55)15
7. DEQUEUE (removes 15)empty
8. ENQUEUE 6262

Option 4: 35 was the front only until the first DEQUEUE. PEEK does not remove it.

Option 1: 15 is removed by the second DEQUEUE (operation 7).

Option 3: 43 is never reached, because only four ENQUEUE operations are performed.

Keyboard Shortcuts

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