Data Structures & AlgorithmsModerate

How many contiguous subarrays of 2 3 1 4 2 2 have a sum EQUAL to their maximum element?

  1. A. 21
  2. B. 6
  3. C. 0
  4. D. 7

Correct answer: B. 6

A subarray with at least two positive elements has sum above its maximum, so only singletons and blocks with zero-valued neighbours can match. Counting ≥ instead of =, using the minimum, or dropping singletons gives different totals.

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

Exams that ask this topic