Data Structures & AlgorithmsModerate

How many contiguous subarrays of 4 2 6 2 5 3 2 7 contain EXACTLY one occurrence of the global minimum value 2?

  1. A. 16
  2. B. 30
  3. C. 14
  4. D. 13

Correct answer: A. 16

Count the occurrences of the global minimum inside each block and keep the blocks with exactly one. Blocks containing the minimum at all, blocks with two or more copies, or excluding singletons each give other totals.

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

Exams that ask this topic