Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Array a = [-2, 5, -1, 4, -3, 6]. How many contiguous subarrays have a sum strictly between 0 and 10?

  1. A. 17
  2. B. 16
  3. C. 20
  4. D. 21

Correct answer: B. 16

Of the 21 subarray sums, 16 lie strictly between 0 and 10; the sums −3, −2, −1, 0 and 11 fail. Allowing a sum of 0 gives 17, dropping the lower bound gives 20, and 21 counts every subarray.

More Coding Interview Problems questions

Exams that ask this topic