The Circular Array
HardAcc. 78.4%
+50 XP 25
Pointer Wraparound
A Circular Queue reuses indices by wrapping the tail and head pointers around using modulo arithmetic: tail = (tail + 1) % size.
The Assignment
Your function receives size, commands, and values.
- Create a fixed-size array.
- Track
head,tail, andcount. - Commands:
- "ENQUEUE": Return true if space exists, else false. (Print the result).
- "DEQUEUE": Return true if not empty, else false. (Print the result).
- "FRONT": Print the front value or -1.
01EXAMPLE 1
Input
size=3, commands=["ENQUEUE", "ENQUEUE", "FRONT"], values=[1, 2, 0]Output
true
true
1Explanation: 1 is at front.
Constraints
- Do not use .shift() (replicate the fixed-memory logic).
Data StructuresQueuePointers
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
size3
commands["ENQUEUE","ENQUEUE","ENQUEUE","ENQUEUE"]
values[1,2,3,4]
Expected Output
true true true false
Click RUN to test your solution