What is a deque (double-ended queue)?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Data Structures & Algorithms development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

A deque (double-ended queue, pronounced "deck") is a linear data structure that supports insertion and deletion from both ends in O(1). It combines the functionality of both a stack and a queue. Operations: addFront/pushFront: O(1); addBack/pushBack: O(1); removeFront/popFront: O(1); removeBack/popBack: O(1); peekFront/peekBack: O(1). Implementation: typically as a doubly linked list or a circular buffer (dynamic array with front/back pointers). Language implementations: Java: ArrayDeque (faster than Stack/LinkedList for stack/queue operations); Python: collections.deque; C++: std::deque. Applications: (1) Sliding window maximum — maintain a monotonic deque of indices (max element always at front); (2) Implementing stack + queue using one structure; (3) Palindrome checking — compare front and back; (4) Undo/redo in text editors; (5) Scheduling algorithms; (6) Deque-based BFS with weights (0-1 BFS). Java ArrayDeque is generally preferred over Stack and LinkedList for LIFO/FIFO operations due to better performance.

Common Mistake

Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Data Structures & Algorithms candidates.