Description

Design a circular queue supporting enQueue, deQueue, Front, Rear, isEmpty, and isFull operations. The circular queue uses fixed-size array efficiently.

Examples

Input:k=3, ["enQueue",1],["enQueue",2],["enQueue",3],["enQueue",4],["Rear"],["isFull"]
Output:[true,true,true,false,3,true]
Explanation:

Queue of size 3 operations.

Input:k = 3, arg2 = [[1],[2],[3],[4]]
Output:false
Explanation:

For k = 3, arg2 = [[1],[2],[3],[4]], the answer is false because the design circular queue condition is not met.

Input:k=2, ["enQueue",5],["Front"],["Rear"],["deQueue"],["isEmpty"],["enQueue",8],["enQueue",9],["deQueue"],["enQueue",7],["Front"],["Rear"]
Output:[true,5,5,true,true,true,true,true,true,8,7]
Explanation:

Queue of size 2: Add 5 (success), front=5, rear=5, remove 5 (success), queue empty, add 8 (success), add 9 (success, queue full), remove 8 (success), add 7 (success), front=9, rear=7. Demonstrates circular behavior when queue wraps around.

Constraints

  • 1 ≤ k ≤ 1000
  • 0 ≤ value ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!