Design Circular Queue is a standard interview problem, often tagged with Array, Linked List, Design, and Queue. It matches LeetCode 622, commonly featured in LinkedIn-style technical interviews for its focus on efficient data structure implementation.[2][3][8]
Design your implementation of a circular queue, which is a linear data structure where operations follow FIFO (First In, First Out) principle. The end connects back to the beginning, allowing reuse of freed space at the front when dequeuing. Implement the MyCircularQueue class:
MyCircularQueue(k): Initializes the queue with a fixed size k.enQueue(value): Inserts value at the rear. Returns true if successful, false if full.deQueue(): Removes and returns true if the front exists, else false.Front(): Returns the front item, or -1 if empty.Rear(): Returns the rear item, or -1 if empty.isEmpty(): Returns true if empty, else false.isFull(): Returns true if full, else false.You must not use built-in queue structures.[3][8][2]
` Input: ["MyCircularQueue", "enQueue", "enQueue", "enQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"] [[3], [1], [2], [3], [4], [], [], [], [4], []] Output: [null, true, true, true, false, -1, true, true, true, 4] Explanation:
Input: ["MyCircularQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"] [[8], [3], [], [], [], [4], []] Output: [null, true, 3, false, true, true, 4]
1 <= k <= 10000 <= value <= 1000enQueue, deQueue, Front, Rear, isEmpty, isFull.
[4][2][3]Array-based uses head/tail pointers with modulo for wrap-around (O(1) operations). Linked list uses nodes with size tracking.[1][3][4]