Data Structures & AlgorithmsModerateCodeforces Div2 B-D · ICPC regional

How many contiguous subarrays [i..j] of [2, 5, 3, 5, 1] have a[i] equal to the maximum of that subarray (ties allowed)?

  1. A. 9
  2. B. 10
  3. C. 7
  4. D. 5

Correct answer: A. 9

The first element is a maximum of a subarray starting at i exactly when it is at least every element to its right within that subarray. Ties are included, so equal later values do not disqualify it.

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

Exams that ask this topic