Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

For the array [14, 10, 15, 11, 15, 18, 12, 2, 5], consider all windows of exactly 5 consecutive elements. What is the sum of the maximum of each window?

  1. A. 87
  2. B. 15
  3. C. 35
  4. D. 72

Correct answer: A. 87

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