Design a fixed-capacity circular queue
AmazonSoftware Engineer · OnsiteLast updated
This question evaluates understanding of fixed-capacity circular queue data structures, array-based indexing, modular arithmetic, and the requirement for constant-time (O(1)) enqueue/dequeue operations.
Design a fixed-capacity circular queue that supports enqueue(x), dequeue(), front(), rear(), isEmpty(), and isFull() operations in O(
- time. Implement it using an array and modular arithmetic. Explain how you manage head and tail indices, how you distinguish between empty and full states, and provide the time and space complexity.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.