Data Structures & AlgorithmsHard

How many contiguous subarrays of [1, 0, 1, 1, 0, 0, 1, 0, 1] contain EXACTLY one 0?

  1. A. 15
  2. B. 39
  3. C. 10
  4. D. 16

Correct answer: A. 15

Count the subarrays by how many zeros they hold, which is the difference between at-least-one and at-least-two counts. A subarray whose two ends are zero can hold more zeros, so it is not the same set.

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

Exams that ask this topic