Data Structures & AlgorithmsVery hardGATE CS

For the array [3, 1, 2, 4, 1, 5, 2, 6], what is the sum of the minimum element over all contiguous subarrays?

  1. A. 24
  2. B. 50
  3. C. 56
  4. D. 61

Correct answer: C. 56

Count how many subarrays each element is the minimum of (the nearest smaller element on the left, nearest smaller or equal on the right) and weight by value; the total is 56. Handling the duplicate 1 inconsistently would double count subarrays containing both 1s.

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

Exams that ask this topic