Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
For the array [19, 15, 11, 1, 9, 17, 11, 8, 9, 18], consider all windows of exactly 4 consecutive elements. What is the sum of the maximum of each window?
- A. 28
- B. 120
- C. 133
- D. 105
Correct answer: B. 120
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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- For the array [12, 2, 20, 18, 17, 2, 20, 6], consider all windows of exactly 3 consecutive elements. What is the sum of the maximum of…
- 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…
- 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…
- For the array [12, 17, 3, 10, 18, 3, 16, 6, 10], consider all windows of exactly 3 consecutive elements. What is the sum of the maximum of…
- For the array [12, 4, 2, 16, 2, 7, 11, 1, 5], consider all windows of exactly 4 consecutive elements. What is the sum of the maximum of…
- 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…