Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

How many contiguous subarrays of [3, 1, 4, 1, 5, 2] have their FIRST element as their maximum (ties count as maximum)?

  1. A. 11
  2. B. 6
  3. C. 10
  4. D. 9

Correct answer: D. 9

For each start i, extend the end while the values stay at most a[i]; each extension is one valid subarray. A nearest-greater-element scan gives the same count in O(n).

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

Exams that ask this topic