Data Structures & AlgorithmsHard

For 3 8 2 9 4 7, compute for every index i the MAXIMUM of the suffix A[i..n−1], then add all these suffix maxima together. What is the total?

  1. A. 21
  2. B. 46
  3. C. 41
  4. D. 50

Correct answer: D. 50

Scan from the right keeping the running maximum; each index contributes the maximum of its suffix. Taking prefix maxima or suffix minima measures other quantities.

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

Exams that ask this topic