Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
Using a monotonic deque, the window maximum for every window of size 3 over [1, 3, -1, -3, 5, 3, 6, 7] is listed left to right. What is the sum of these window maxima?
- A. -4
- B. 29
- C. 28
- D. 23
Correct answer: B. 29
Windows give maxima 3, 3, 5, 5, 6, 7 which sum to 29. The sum of window minima is a different quantity, and using window size 2 changes the list.
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
- In the array [1, 2, 1, 3, 2, 5] exactly two values appear once and every other value appears twice. Which two values are they, as a sorted…
- What is the value of sum of popcount(i) for i from 1 to 20 (number of 1-bits in the binary form of each i, summed)?
- For the array [6, 12, 5, 8], what is the sum of (x & -x) over all elements x, where x & -x is the lowest set bit of x?
- How many contiguous subarrays of [1, 2, 4, 3, 6] have a bitwise OR equal to exactly 7?
- How many distinct non-empty substrings does the string "abacaba" have?
- In the string "ababababa", how many times does "aba" occur, counting overlapping occurrences?