Problem Statement
Which structure gives O(1) appends and pops at both ends for queues?
Explanation
A deque is a double-ended queue optimized for fast appends and pops at both left and right. Lists are fast at the right end but slow for pops from the left.
Choose deque for FIFO queues, sliding windows, and bounded buffers.
Code Solution
SolutionRead Only
from collections import deque q=deque() q.append(1); q.append(2); q.popleft()
