Design Circular Deque
Implement MyCircularDeque(k), a capacity-limited deque with insertFront(value), insertLast(value), deleteFront(), deleteLast(), getFront(), getRear(),…
Implement MyCircularDeque(k), a capacity-limited deque with insertFront(value), insertLast(value), deleteFront(), deleteLast(), getFront(), getRear(), isEmpty() and isFull(). Insertions/deletions return a strict boolean indicating success. Insertion into a full deque and deletion from an empty deque return false without mutation. Endpoint reads return the stored strict integer, or -1 when empty. Values may themselves be -1; use isEmpty to distinguish occupancy. Return one aligned result per call, with null for construction.
- `operations` and `arguments` are aligned arrays with 1–1,001 total records, including one initial `MyCircularDeque` constructor with `[k]`. - Capacity `k` is a strict integer from 1 to 1,000. Each insertion takes one strict signed-int32 value from −2,147,483,648 to 2,147,483,647, including −1 and 0. - All other methods have no arguments. Other methods, repeated constructors, booleans and fractional arguments are invalid. - Duplicate values remain distinct occurrences. Failed operations and queries preserve state; caller input arrays remain unchanged. - Teaching traces use at most 12 records, capacity 1–8 and values −99 to 99. Coding retains the full bounds above.
Example 1: input operations = ["MyCircularDeque","insertLast","insertLast","insertLast","deleteFront","insertLast","getFront","getRear","isFull"], arguments = [[3],[7],[2],[9],[],[4],[],[],[]]; output [null,true,true,true,true,true,2,4,true]. After front removal, reusing the freed slot preserves logical order [2,9,4]. Physical slot order is not front-to-rear order.
Example 2: input operations = ["MyCircularDeque","getFront","isEmpty","insertLast","getFront","isEmpty","insertFront","deleteLast","deleteLast","isEmpty"], arguments = [[1],[],[],[-1],[],[],[8],[],[],[]]; output [null,-1,true,true,-1,false,false,true,false,true]. A read returning-1 can refer to stored-1 or an empty deque; isEmpty distinguishes these states. Full insertion and empty deletion do not change state.
Category: Queues. Topic: queue. Difficulty: Medium. Patterns: linear-scan.