Data Structures & AlgorithmsHardGATE CS · ICPC regional
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 each window?
- A. 126
- B. 120
- C. 105
- D. 24
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, 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…
- In the undirected connected graph on vertices 0 to 8 with edges 0-1, 0-3, 0-4, 0-5, 1-2, 1-3, 2-4, 2-5, 2-6, 3-7, 5-6, 7-8, how many…
- In the undirected connected graph on vertices 0 to 7 with edges 0-1, 0-5, 0-6, 1-2, 1-4, 2-3, 2-6, 3-5, 4-7, 6-7, how many vertices are at…