17 · Queues & Deques

#641 Design Circular Deque

Mediumsolve on LeetCode ↗

frequently reported atAmazon

the problem

In plain words

Implement a fixed-capacity double-ended queue MyCircularDeque(k): insertFront, insertLast, deleteFront, deleteLast (return true/false), getFront, getRear (−1 if empty), isEmpty, isFull.

in k = 3; insertLast(1), insertLast(2), insertFront(3), insertFront(4), getRear(), isFull(), deleteLast(), insertFront(4), getFront()

out true, true, true, false, 2, true, true, true, 4

  • 1 ≤ k ≤ 1000
  • 0 ≤ value ≤ 1000
  • At most 2000 calls

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

Design: implement every operation. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #622
      Design Circular Queue
      Mediumin Queues
    2. #239