Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

  1. A. 106
  2. B. 44
  3. C. 54
  4. D. 104

Correct answer: D. 104

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