Skip to main content
LeetCode 622, Medium. Topics: Array, Linked List, Design, Queue. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 15 parametrized pytest cases, and a playground notebook:

Problem

Design your implementation of the circular queue. The circular queue is a linear data structure that operates on the FIFO (First In First Out) principle, with the last position connected back to the first to form a circle (a “Ring Buffer”). Implement the MyCircularQueue class:
  • MyCircularQueue(k) Initializes the object with the queue size k.
  • int Front() Gets the front item; returns -1 if empty.
  • int Rear() Gets the last item; returns -1 if empty.
  • boolean enQueue(int value) Inserts an element. Returns true if successful.
  • boolean deQueue() Deletes an element from the queue. Returns true if successful.
  • boolean isEmpty() Checks whether the queue is empty.
  • boolean isFull() Checks whether the queue is full.
You must solve the problem without using the built-in queue data structure.

Examples

Constraints

  • 1 <= k <= 1000
  • 0 <= value <= 1000
  • At most 3000 calls will be made to enQueue, deQueue, Front, Rear, isEmpty, and isFull.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode 250, NeetCode All.
Last modified on August 25, 2026