Deque

Domain: Data Structures

🎯 Motivation

A deque (double-ended queue) lets you add and remove from both ends, combining stack and queue flexibility.

📋 Concrete Example

from collections import deque; d = deque([1,2,3]); d.appendleft(0); d.pop() gives 3. You can operate on both ends.

🔗 Analogy

A train with doors on both ends. Passengers can board or exit from either the front or the back of the train.