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.

  1. Create a fixed-size array.
  2. Track head, tail, and count.
  3. 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

Inputsize=3, commands=["ENQUEUE", "ENQUEUE", "FRONT"], values=[1, 2, 0]
Outputtrue true 1

Explanation: 1 is at front.

Constraints

  • Do not use .shift() (replicate the fixed-memory logic).
Data StructuresQueuePointers
JavaScript
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