Skip to interview prep
Apexed

17. Why use a circular array for a queue?

MediumQueues

Technical
Show model answer

With a plain array, dequeuing from the front either shifts every element (O(n)) or wastes the space at the front. A circular buffer keeps front and rear indices that wrap around with modulo arithmetic, so enqueue and dequeue are O(1) and space is reused. Track the count (or leave one slot empty) to tell full from empty.

Why use a circular array for a queue — Data structures & algorithms interview question — Apexed