Data Structures & AlgorithmsHard

For 5 3 8 1 4 2, compute for every index i the MINIMUM of the prefix A[0..i], then add all these prefix minima together. What is the total?

  1. A. 14
  2. B. 42
  3. C. 23
  4. D. 15

Correct answer: A. 14

The running minimum changes only when a new smaller value appears, so the total is a sum of stair-step values. Using the suffix minimum, prefix maxima, or the plain array sum answers different questions.

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

Exams that ask this topic