Fixed-Capacity Ring Buffer Queue

Asked at ByteDance · Coding Questions · Difficulty: Medium

Build a first-in-first-out queue that holds at most `k` values and stores them in a fixed-size ring: once the end of the storage is reached, new values reuse the free slots at the beginning, so no slot is wasted and the storage never grows.

Loading the problem…