Data Structures19 sections · 729 units
Open in Course

The Limitation of Queues

Single-ended access

Queues only let you add at the back and remove from the front. Sometimes you need more flexibility.

Consider the sliding window maximum problem: find the maximum in each window of size kk as it slides through an array.

With a basic queue, you can't efficiently track the maximum. You need access to both ends, and you need to remove elements from either end. Enter the deque.