Data Structures & AlgorithmsHardTCS Digital · Infosys SP
A monotonic deque reports the maximum of every window of size 3 in [19, 6, 7, 16, 10, 2, 12, 8, 17]. What is the SUM of all reported window maxima?
- A. 101
- B. 108
- C. 127
- D. 92
Correct answer: B. 108
Window maxima: [19, 16, 16, 16, 12, 12, 17], summing to 108. 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
- Two pointers start at both ends of the sorted array [3, 4, 5, 6, 8, 17, 18, 23, 26, 27]. How many pairs (i < j) have a[i] + a[j] ≤ 40?…
- What does this loop-counting code print? (Python) python n, c = 20, 0 i = n while i > 0: for j in range(i): c += 1 i //= 2 print(c)
- Rabin–Karp with base 10 and a deliberately small modulus counts true matches and spurious hits (hash equal, text different). What is…
- Using a sliding window with a last-seen index map, what is the length of the longest substring of "beeebdddcbadad" with all characters…
- What is the length of the smallest substring of "bcdadddaacbac" that contains every distinct character of the string at least once?…
- Which lower bound holds for every comparison-based sorting algorithm in the worst case?