Data Structures & AlgorithmsHardGATE CS · DSA
A monotonic deque reports the maximum of every window of size 3 in [0, 13, 9, 1, 2, 18, −1, −3, 17]. What is the SUM of all reported window maxima?
- A. 106
- B. 119
- C. 97
- D. 72
Correct answer: A. 106
Window maxima: [13, 13, 9, 18, 18, 18, 17], summing to 106. Taking the 7 largest elements overall double-counts big values that dominate several windows only once.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- An array of 8 zeros (indices 0–7) receives range updates with a difference array (diff[l] += v, diff[r + 1] −= v, then prefix-sum): add 5…
- What is the minimum number of swaps (of any two elements) needed to bring all the 1s of [1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0] together into…
- Reverse the order of words, collapsing multiple spaces. What is printed? python s = " new the is oil " w = s.split() print("|" + "…
- You must answer many queries 'sum of A[l..r]' while also updating single elements, on an array of n elements. Which choice gives O(log n)…
- An array of 8 integers holds values 1..7 with exactly one value appearing twice: [6, 5, 7, 4, 3, 2, 1, 1]. Treating i → a[i] as a linked…
- Overlapping versus non-overlapping substring counts. What is printed? python s, p = "aabaabbbabab", "bab" over = sum(1 for i in…