Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

What is the sum of the minimum over all contiguous subarrays of [3, 1, 2, 4] that have length at least 2?

  1. A. 8
  2. B. 7
  3. C. 9
  4. D. 11

Correct answer: B. 7

Subarrays of length at least 2 are the pairs, triples and the full array; their minima are 1, 1, 1, 2, 1, 1 (not all of them). Summing these gives the total.

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

Exams that ask this topic