Data Structures & AlgorithmsVery hard

Which statement about a monotonic deque for sliding-window minimum is correct?

  1. A. Each index is pushed and popped at most once, so the total work over the whole scan is linear.
  2. B. Each window costs O(k) work, so the total is O(nk).
  3. C. The deque must be rebuilt from scratch for every window.
  4. D. The deque stores the values in decreasing order and keeps the largest one at the back.

Correct answer: A. Each index is pushed and popped at most once, so the total work over the whole scan is linear.

Every element enters and leaves the deque at most once, which keeps the scan linear. Rebuilding for each window or storing values in the wrong order breaks the amortized bound.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic