141. In a circular array queue, how do you tell a full queue from an empty one?
MediumQueues
Technical
Show model answer
With `front` and `rear` indices that wrap modulo capacity, both full and empty can leave `front == rear`, so you need one extra piece of information. Common fixes: keep a size counter (empty when size is 0, full when it equals capacity); or deliberately leave one slot unused so empty is `front == rear` and full is `(rear + 1) % capacity == front`; or keep a boolean recording whether the last operation was an enqueue.
All variants keep enqueue and dequeue at O(1). The counter is the clearest; the one-empty-slot rule avoids an extra field and is common in lock-free single-producer/single-consumer buffers.