Data Structures & AlgorithmsHard

How many contiguous subarrays of 1 5 2 7 3 4 8 contain EXACTLY one element whose value is at least 5?

  1. A. 13
  2. B. 23
  3. C. 15
  4. D. 8

Correct answer: A. 13

Count the elements at least 5 inside each subarray and keep the blocks with exactly one. Using at-least-one, using a strict bound of 5, or allowing two large values each change the total.

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

Exams that ask this topic