641. Design Circular Deque
Practice Design Circular Deque for free on NudgeCode: Medium, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design a double-ended queue with a fixed capacity k, backed by a circular buffer (don't use a built-in deque).
insertFront(value)/insertLast(value)add an item at the front / back; returntrueon success,falseif the deque is full.deleteFront()/deleteLast()remove the front / back item; returntrueon success,falseif the deque is empty.getFront()/getRear()return the front / back item, or-1if the deque is empty.isEmpty()/isFull()report whether the deque is empty / full.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for the constructor).
Example
["MyCircularDeque","insertLast","insertLast","insertFront","insertFront","getRear","isFull","deleteLast","insertFront","getFront"]
[[3],[1],[2],[3],[4],[],[],[],[4],[]]
-> [null,true,true,true,false,2,true,true,true,4]
Constraints
- 1 <= k <= 1000
- 0 <= value <= 1000
- Up to 2000 calls in total