The Queue Protocol (FIFO)
EasyAcc. 97.2%
+15 XP 5
The Waiting Line (FIFO)
A Queue is modeled after a real-world waiting line. It follows the FIFO (First-In, First-Out) principle: the first person to join the line is the first one to be served. Think of a printer handling documents or customers waiting at a store.
The Assignment
Your mission is to build a queue manager. Your function receives an array of commands and corresponding values.
- Initialize an empty array to serve as your internal queue.
- Iterate through the
commands:- If the command is "ENQUEUE", add the value to the back of the queue.
- If the command is "DEQUEUE", remove the element from the front and print it.
- If the command is "FRONT", print the front element without removing it.
01EXAMPLE 1
Input
["ENQUEUE", "ENQUEUE", "DEQUEUE"], [10, 20, 0]Output
10Explanation: 10 was enqueued first.
Constraints
- Use `push` and `shift` (or manual indexing).
Data StructuresQueue
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
commands["ENQUEUE","DEQUEUE"]
values[10,0]
Expected Output
10
Click RUN to test your solution