Loading practice problems…
Loading your practice workspace…
Loading code editor…
28 / 29
Sign in
Algorithms/Queue

Design Circular Queue

medium35 min

Process operations on a fixed-capacity circular queue without shifting existing items.

Return one output per operation. The constructor produces null; enqueue and dequeue return booleans; Front, Rear, isEmpty, and isFull return their values.

Example 1

Inputoperations = ["MyCircularQueue", "enQueue", "enQueue", "enQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"], values = [[3], [1], [2], [3], [4], [], [], [], [4], []]

Output[null, true, true, true, false, 3, true, true, true, 4]

Example 2

Inputoperations = ["MyCircularQueue", "Front", "Rear", "isEmpty"], values = [[2], [], [], []]

Output[null, -1, -1, true]

Constraints

  • 1 ≤ capacity ≤ 1,000
  • At most 3,000 operations are performed.
QueueCircular BufferDesign