Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

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

  1. A. 17
  2. B. 14
  3. C. 15
  4. D. 29

Correct answer: C. 15

Enumerate the six subarrays of length at least two and add their minima. Including the four singletons (the last trap option) adds their values to the total.

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

Exams that ask this topic