Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

Sum the maximum of every contiguous window of length 3 in the array [1, 3, -1, -3, 5, 3, 6, 7] (there are n − k + 1 windows). What is the total?

  1. A. -4
  2. B. 7
  3. C. 29
  4. D. 26

Correct answer: C. 29

A monotonic deque holds indices with decreasing values inside the current window, so the front is always the window maximum in O(n). Summing the minima instead of the maxima, or reading only the final window, gives a different total.

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

Exams that ask this topic