Data Structures & AlgorithmsVery hardGATE CS · competitive programming

A window of length 3 slides over [1, 3, −1, −3, 5, 3, 6, 7]. What is the sum of the maximum of each window?

  1. A. −4
  2. B. 24
  3. C. 33
  4. D. 29

Correct answer: D. 29

The window maxima are 3, 3, 5, 5, 6, 7, summing to 29. A monotonic deque finds each maximum in O(1) amortised time. The sum of minima, −4, is the trap for a flipped comparison.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic