Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: For the array [3, 1, 4, 1, 5, 9, 2] and window size 3, compute the sum of the minimum of every contiguous window.

  1. A. 31
  2. B. 6
  3. C. 4
  4. D. 11

Correct answer: B. 6

The five windows have minima 1, 1, 1, 1, 2, summing to 6 (a monotonic deque gives O(n)). Summing window maxima gives 31, missing the last window gives 4, and using window size 2 gives 11.

More Coding Interview Problems questions

Exams that ask this topic