Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Design Circular Queue

Medium

Topics
ArrayQueueDesign

Design a circular queue using a fixed-size array. Implement MyCircularQueue(k) and: enQueue(value) (returns true on success), deQueue() (returns true on success), Front() and Rear() (return the front/rear value or -1 if empty), isEmpty(), and isFull().

Example 1

Input:  operations = ["MyCircularQueue","enQueue","enQueue","enQueue","enQueue","Rear","isFull","deQueue","enQueue","Rear"], values = [[3],[1],[2],[3],[4],[],[],[],[4],[]]
Output: [null,true,true,true,false,3,true,true,true,4]

Constraints

  • 1 <= k <= 1000
  • 0 <= value <= 1000
  • At most 3000 calls.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access