Queue Operations Simulator

Queues Data Structures Simulation Easy

Problem: Queue Operations Simulator

You are tasked with implementing a simple queue simulator that processes a sequence of queue operations. The queue should operate on a First-In-First-Out (FIFO) basis.

Operations to Support

  • enqueue X: Add the element X to the end of the queue. (No output for this operation.)
  • dequeue: Remove and return the element from the front of the queue. If the queue is empty, return -1.
  • peek: Return the element at the front of the queue without removing it. If the queue is empty, return -1.
  • size: Return the current number of elements in the queue.

Input

A list of operations as strings (e.g., ["enqueue 5", "enqueue 3", "peek", "dequeue", "size"]).

Output

A list of outputs corresponding to the operations that produce a result (i.e., for dequeue, peek, and size).

Example

For the input:

["enqueue 10", "enqueue 20", "peek", "size", "dequeue", "dequeue", "dequeue"]

The output should be:

[10, 2, 10, 20, -1]

Notes

  • Process the operations in the given order.
  • You may assume that the input is well-formatted.
  • This problem ties into the concept of queue operations and is a good exercise to understand how queues work in data structures. Happy coding on this lovely spring day in early March 2025!

Implement your solution using the starter code provided below.