Quant Memo
Coding/●●●●

A fixed-size ring buffer for the last N ticks

You want to retain only the most recent N ticks from an endless stream, in fixed memory. Implement a circular (ring) buffer that overwrites the oldest tick once full and can report its contents oldest-to-newest.

capacity 3: push 10, 20, 30  -> recent = [10, 20, 30]
push 40                      -> recent = [20, 30, 40]   # 10 evicted

Implement push and a recent() readout in O(1) push time and O(N) space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions