Data Structures & AlgorithmsHard

What is the sum, over all contiguous subarrays of [3, 1, 3, 2], of the maximum element of each subarray?

  1. A. 33
  2. B. 27
  3. C. 21
  4. D. 16

Correct answer: B. 27

Each subarray must be credited to exactly one position of its maximum. Left side stops at a value ≥ a[i] and right side stops at a value > a[i], which gives the unique owner when two equal maxima exist.

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

Exams that ask this topic