622. Design Circular Queue
Practice Design Circular Queue for free on NudgeCode: Medium, Linked List pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design a fixed-size FIFO queue backed by a circular buffer of capacity k, so freed slots at the front get reused.
enQueue(value)adds to the back; returnsfalseif the queue is full.deQueue()removes from the front; returnsfalseif the queue is empty.Front()/Rear()return the first / last value, or-1if empty.isEmpty()/isFull()report the state.
Do not use a built-in queue type.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for the constructor and for calls that return nothing).
Example
["MyCircularQueue","enQueue","enQueue","enQueue","enQueue","Rear","isFull","deQueue","enQueue","Rear"]
[[3],[1],[2],[3],[4],[],[],[],[4],[]]
-> [null,true,true,true,false,3,true,true,true,4]
Constraints
- 1 <= k <= 1000
- 0 <= value <= 1000
- Up to 3000 calls in total