Data Structures & AlgorithmsVery hard

For every contiguous window of size 3 in 4 2 12 3 8 1 7, take its minimum and add all these minimums. What is the total?

  1. A. 9
  2. B. 52
  3. C. 29
  4. D. 12

Correct answer: A. 9

Each window contributes its minimum once, and the monotonic deque gives each minimum in amortized O(1). Summing maxima, taking the first element of each window, or using windows of size 2 changes the total.

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

Exams that ask this topic