Hints — p98 Design Circular Queue

  1. State = arr: List[int] of size k + front: int + size: int. Avoid storing rear directly — derive it.

  2. Next write index = (front + size) % k. Rear index = (front + size - 1) % k.

  3. Full vs empty disambiguation: with a size counter, size == 0 means empty and size == k means full. No pointer-comparison ambiguity.

  4. Front() / Rear() on empty must return -1 (per LC spec); don’t index into arr.

  5. Real-world: this is a ring buffer. Production extensions: lock-free via atomic head/tail (SPSC: easy; MPMC: hard — see LMAX Disruptor); cache-line padding to avoid false sharing.

If stuck: see solution.py.