Data Structures & AlgorithmsHardGATE CS · DSA
A monotonic deque reports the maximum of every window of size 3 in [14, 5, −3, 14, 5, 14, −5, 16, 4]. What is the SUM of all reported window maxima?
- A. 116
- B. 100
- C. 102
- D. 91
Correct answer: C. 102
Window maxima: [14, 14, 14, 14, 14, 16, 16], summing to 102. 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
- Delete duplicates from a SORTED linked list. Version A keeps one copy of each value; version B removes every value that appears more than…
- Which data structure gives O(1) worst-case time for inserting and deleting at BOTH ends and also O(1) access by index?
- What is the length of the shortest contiguous subarray of [1, 3, 5, 6, 3, 3, 7, 9, 4, 9] whose sum is at least 20? (All values are…
- Count zero-sum contiguous subarrays with a prefix-sum frequency map. What is printed? python from collections import defaultdict a = [1…
- Bubble sort (ascending; each pass compares adjacent pairs left to right and swaps if out of order) is applied to [5, 42, 29, 4, 41, 8, 53…
- Stock prices over 8 days are [27, 32, 42, 42, 35, 66, 59, 31]. The span of day i is the number of consecutive days ending at day i…