Design Circular Queue
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement a bounded FIFO queue, MyCircularQueue, backed by a fixed-size buffer whose end wraps around to its start (a ring buffer).
- MyCircularQueue(k) creates an empty queue that can hold at most k elements.
- enQueue(value) adds value at the rear. Returns true on success, or false if the queue is full.
- deQueue() removes the front element. Returns true on success, or false if the queue is empty.
- Front() returns the front element, or -1 if the queue is empty.
- Rear() returns the last element, or -1 if the queue is empty.
- isEmpty() / isFull() report whether the queue holds zero / k elements.
Do not use a built-in queue type. Every operation must run in O(1).
Examples
Constraints
- 1 <= k <= 1000
- 0 <= value <= 1000
- At most 3000 calls are made in total.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.