Questions: Deques and Double-Ended Queues

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

You need to find the maximum value in every window of size k as it slides across an array of n elements. Which approach correctly uses a deque to solve this in O(n)?

AStore all k elements in the deque for each window and scan for the max — O(k) per window
BMaintain a deque of indices in decreasing value order, removing expired indices from the front and smaller indices from the back as each new element arrives
CUse the deque as a sorted set, inserting in order at each step
DPush all elements onto the deque and pop the front k times per window
Question 2 Multiple Choice

A deque is implemented with a circular array. Which statement best describes the trade-off compared to a doubly linked list implementation?

AThe circular array is slower because it must check for wraparound on every operation
BThe doubly linked list has better cache locality because elements are stored sequentially in memory
CThe circular array has better cache locality and avoids per-element pointer overhead, but requires occasional resizing
DBoth implementations have identical performance characteristics
Question 3 True / False

A deque can simulate both a stack (LIFO) and a queue (FIFO) by choosing which ends to use for insertion and removal.

TTrue
FFalse
Question 4 True / False

A deque's O(1) performance at both ends makes it strictly slower than a dedicated stack or queue for applications that mainly need one-ended access.

TTrue
FFalse
Question 5 Short Answer

Explain why a deque, rather than a simple queue or stack, is the right data structure for the sliding window maximum problem.

Think about your answer, then reveal below.