Data Structures & AlgorithmsHardGATE CS · ICPC regional

For the array [19, 2, 19, 13, 13, 7, 16, 11, 5, 1], consider all windows of exactly 3 consecutive elements. What is the sum of the maximum of each window?

  1. A. 129
  2. B. 152
  3. C. 44
  4. D. 48

Correct answer: A. 129

Each window contributes its maximum; a monotonic deque does this in O(n). The window minima, a window of the wrong size, or non-overlapping blocks give different sums.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic