Code Room
CodingMediumcod-g592
Subject Circular bufferLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.