Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

How many index pairs i < j in [2, 5, 3, 4, 1] satisfy a[i] < a[j] and every element strictly between i and j is at most a[j]?

  1. A. 2
  2. B. 3
  3. C. 1
  4. D. 4

Correct answer: A. 2

The condition describes the pairs that a monotonic stack reveals when it pops elements smaller than the current value. Counting all increasing pairs (last option) ignores the between condition.

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

Exams that ask this topic