Code RoomCircular deque
MediumPrep Room Coding #921

Circular deque

CodingAlgorithms & data structuresMid–Senior~25 min

Implement a fixed-capacity circular deque (size k) backed by an array. Process ops: ['insertFront', x] / ['insertLast', x] add to the front/back and return True, or False if full; ['deleteFront'] / ['deleteLast'] remove from the front/back and return True, or False if empty; ['getFront'] / ['getRear'] return the front/rear value or -1 if empty; ['isEmpty'] / ['isFull'] return booleans. Return the list of results for every op, in order. k >= 1.

Implement
circular_deque(k: int, ops: list[list]) → list
Examples
in[3,[["insertLast",1],["insertLast",2],["insertFront",3],["insertFront",4],["getRear"],["isFull"],["deleteLast"],["insertFront",4],["getFront"]]]out[true,true,true,false,2,true,true,true,4]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[3,[["insertLast",1],["insertLast",2],["insertFront",3],["insertFront",4],["getRear"],["isFull"],["deleteLast"],["insertFront",4],["getFront"]]][true,true,true,false,2,true,true,true,4]not run yetsample