Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the sum of the minimum element over all contiguous subarrays of [5, 3, 1, 4, 2]?

  1. A. 28
  2. B. 29
  3. C. 26
  4. D. 31

Correct answer: A. 28

For each element, count the subarrays where it is the minimum using its left and right boundaries from a monotonic stack. Summing the minimum of each subarray directly is the brute method.

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

Exams that ask this topic