Implement Queue Using Array
Implement a queue using an array and execute a sequence of operations.
You are given two parallel arrays, operations and values, of equal length. For each index i:
enqueue(x)whenoperations[i] == "enqueue": pushvalues[i]to the back of the queue.dequeue()whenoperations[i] == "dequeue": remove the front element if present (no output).front()whenoperations[i] == "front": append the front element to the output, or-1if the queue is empty.empty()whenoperations[i] == "empty": append1if the queue is empty, otherwise0.
For non-enqueue operations, values[i] is a placeholder 0 and must be ignored.
Return the output array in order.
Examples
Input: [["enqueue","enqueue","front","dequeue","front"],[1,2,0,0,0]]
Output: [1,2]
Input: [["enqueue","front"],[5,0]]
Output: [5]
Hints
A plain array with a moving head index avoids shifting elements on every dequeue.
For `enqueue`, read and consume `values[i]`; for other operations ignore `values[i]`.
Only `front()` and `empty()` produce output values.
Related Problems
Implement Queue Using Array
Implement a queue using an array and execute a sequence of operations.