Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

How many contiguous subarrays of [3, 1, 3, 2, 3, 1] have their maximum value occurring EXACTLY twice inside the subarray?

  1. A. 8
  2. B. 5
  3. C. 21
  4. D. 6

Correct answer: D. 6

Brute force over subarrays with a count of the maximum, or a monotone stack giving for each element the span where it is the maximum. Counting subarrays where the maximum appears at least once is a different (larger) quantity.

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

Exams that ask this topic