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?
- A. 106
- B. 44
- C. 54
- 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.
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 [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…
- In the undirected connected graph on vertices 0 to 9 with edges 0-1, 0-3, 0-9, 1-2, 1-5, 1-9, 2-9, 3-4, 3-6, 3-8, 5-6, 5-7, how many…