Code RoomCircular buffer
MediumPrep Room Coding #1529

Circular buffer

CodingStorage & CDNEntry–Mid~20 min

Implement a fixed-size circular (ring) buffer of capacity `capacity`. Process operations: ["push", x] appends x; if the buffer is full, the oldest element is overwritten (dropped) to make room. ["pop"] removes and conceptually returns the oldest element (a no-op if empty). ["snapshot"] yields the current buffer contents from oldest to newest. Return a list containing one entry per snapshot operation, each being the list of current contents oldest-to-newest. capacity is a positive integer.

Implement
ring_buffer(capacity: int, ops: list[list]) → list[list]
Examples
in[3,[["push",1],["push",2],["push",3],["push",4],["snapshot"]]]out[[2,3,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 20 min
InputExpectedGot
[3,[["push",1],["push",2],["push",3],["push",4],["snapshot"]]][[2,3,4]]not run yetsample