Data Structures & AlgorithmsVery hard

How many contiguous subarrays of 4 2 7 1 5 3 6 of length at least 2 have their FIRST element equal to their minimum?

  1. A. 12
  2. B. 6
  3. C. 4
  4. D. 5

Correct answer: D. 5

The first element must not be exceeded by any element that follows in the block, so the qualifying blocks end before the next smaller value. Including singletons, testing the last element, or testing the maximum changes the answer.

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

Exams that ask this topic