Data Structures & AlgorithmsVery hard

A monotonic deque for sliding-window maximum stores array INDICES instead of values. Why?

  1. A. Indices are needed to compare values faster than the values themselves.
  2. B. Indices let the algorithm detect when the front element has slid out of the window (its index is too small).
  3. C. Only indices can be stored in a queue.
  4. D. Indices remove the need to pop smaller elements.

Correct answer: B. Indices let the algorithm detect when the front element has slid out of the window (its index is too small).

Each stored index can be compared against the current window start to decide whether to evict the front, and the values are still read from the array. Storing values alone would make expiry impossible to detect.

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

Exams that ask this topic