Code RoomCircular deque
MediumPrep Room Coding #1159

Circular deque

CodingAlgorithms & data structuresMid–Senior~30 min

Design a circular double-ended queue with a fixed capacity. Support operations replayed in order: ["insertFront", x], ["insertLast", x], ["deleteFront"], ["deleteLast"], ["getFront"], ["getRear"]. The four mutating ops append 1 to results if they succeed and 0 if the deque is full/empty; getFront/getRear append the value or -1 if empty. Return the full results list. Capacity is between 1 and 1000.

Implement
circular_deque(capacity: int, ops: list[list]) → list[int]
Examples
in[3,[["insertLast",1],["insertLast",2],["insertFront",3],["insertFront",4],["getRear"],["getFront"],["deleteLast"],["insertFront",4],["getFront"]]]out[1,1,1,0,2,3,1,1,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 30 min
InputExpectedGot
[3,[["insertLast",1],["insertLast",2],["insertFront",3],["insertFront",4],["getRear"],["getFront"],["deleteLast"],["insertFront",4],["getFront"]]][1,1,1,0,2,3,1,1,4]not run yetsample