On February 22, a day associated with leadership and order, implement a queue simulator that processes a series of operations. The operations are provided in an array of strings, where each string represents one of the following commands:
x
to the end of the queue. x
will always be a positive integer.null
(or equivalent in your language).You will also be provided with an integer representing the maximum capacity of the queue. If an ENQUEUE
operation is attempted when the queue is at full capacity, ignore that operation.
Your task is to implement the function processQueueOperations(operations, capacity)
which processes the operations and returns an object containing the final state of the queue and an array of results recorded from the PEEK
commands in the order they were encountered.
Example
Input:
operations = ["ENQUEUE 10", "ENQUEUE 20", "PEEK", "DEQUEUE", "PEEK", "ENQUEUE 30"], capacity = 3
Output:
{
"queue": [20, 30],
"peekResults": [10, 20]
}
Implement the solution ensuring that all operations are handled according to the description.