Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Array [2, 3, 5, 10, 2, 0, 1]. How many contiguous non-empty subarrays have a sum equal to exactly twice their maximum element?

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

Correct answer: A. 5

Checking every subarray directly is enough for this small array. Comparing the maximum with the sum without the factor of two counts a different set of subarrays.

More Coding Interview Problems questions

Exams that ask this topic