5. You need to process tasks in the exact order they arrive but also want to peek at the next task without removing it. Which queue operation combination solves this best?
hard
A. Use push() to add, shift() to remove, and access queue[0] to peek.
B. Use unshift() to add, pop() to remove, and access queue[queue.length-1] to peek.
C. Use push() to add, pop() to remove, and access queue[queue.length-1] to peek.
D. Use unshift() to add, shift() to remove, and access queue[0] to peek.
Solution
Step 1: Understand queue order and operations
Queue adds at end (push), removes from front (shift) to keep FIFO order.
Step 2: Identify how to peek without removing
Peeking means looking at the front element without removing it, which is queue[0].
Final Answer:
Use push() to add, shift() to remove, and access queue[0] to peek. -> Option A