Circular deque

Write codeMedium30 min

Your task

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.

Examples

circular_deque(capacity: int, ops: list[list]) -> list[int]
Example 1
Inputcircular_deque(3, [["insertLast", 1], ["insertLast", 2], ["insertFront", 3], ["insertFront", 4], ["getRear"], ["getFront"], ["deleteLast"], ["insertFront", 4], ["getFront"]])
Output[1, 1, 1, 0, 2, 3, 1, 1, 4]