Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
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 each window?
- A. 38
- B. 100
- C. 118
- D. 27
Correct answer: C. 118
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 [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…
- In the undirected connected graph on vertices 0 to 6 with edges 0-1, 1-2, 1-5, 1-6, 2-3, 2-4, 2-5, 3-5, 5-6, how many vertices are at…