A deque lets you add and remove elements from both the front and the back. With a ring buffer or linked list, these operations are O(1).
Advanced answer
Deep dive
A deque (double-ended queue) supports O(1) insertion/removal at both ends: addFirst/addLast and removeFirst/removeLast. In practice it is often array-backed using a circular buffer (great cache locality) or implemented as a linked list.
A deque can act as:
Queue (FIFO): addLast + removeFirst
Stack (LIFO): addLast + removeLast
Examples
ArrayDeque<Integer> d = new ArrayDeque<>();
d.addLast(1);
d.addLast(2);
int first = d.removeFirst(); // 1
d.addFirst(10);
int last = d.removeLast(); // 2
Where it shows up
BFS: push neighbors to the back, pop from the front.
Sliding window / monotonic queue patterns (e.g., max in window).
0-1 BFS: push weight-0 edges to front and weight-1 edges to back.
Common pitfalls
Deque is not for random access; removing from the middle is O(n)