Data Structures & AlgorithmsHard

How many contiguous subarrays of 1 4 2 6 3 5 0 have their FIRST element equal to their minimum AND their LAST element equal to their maximum (length 1 subarrays count)?

  1. A. 16
  2. B. 4
  3. C. 11
  4. D. 12

Correct answer: C. 11

The condition needs the left end to be the minimum and the right end to be the maximum of the same subarray, which holds for singletons trivially. Reversing the roles, testing one end only, or dropping singletons each change the total.

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

Exams that ask this topic