Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

For the array [2, 12, 13, 2, 4, 15, 15, 5, 20, 16, 17, 9], consider all windows of exactly 4 consecutive elements. What is the sum of the maximum of each window?

  1. A. 138
  2. B. 36
  3. C. 48
  4. D. 151

Correct answer: D. 151

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