Data Structures & AlgorithmsVery hard

How many contiguous subarrays of 0 1 2 0 1 2 have a sum between 3 and 5 inclusive?

  1. A. 9
  2. B. 10
  3. C. 3
  4. D. 12

Correct answer: B. 10

Zeros create many subarrays with equal sums, so the counting must treat each start and end pair separately. Using a strict bound on either end, or ignoring the upper bound, each change the total.

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

Exams that ask this topic