Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many subarrays [i..j] of [3, 1, 4, 1, 5] have their first element strictly greater than every other element of the subarray?

  1. A. 15
  2. B. 2
  3. C. 5
  4. D. 7

Correct answer: D. 7

For each start the valid ends form a prefix: 3 gives [3], [3,1]; 1 gives [1]; 4 gives [4], [4,1]; then [1] and [5], total 7. Excluding singletons gives 2, counting only singletons 5, and 15 every subarray.

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

Exams that ask this topic