Data Structures & AlgorithmsHard

How many contiguous subarrays of 3 1 6 2 9 4 5 12 contain EXACTLY 2 multiples of 3?

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

Correct answer: D. 10

Count the multiples of 3 inside each subarray, then keep the ones with exactly two. Using at-most or at-least bounds, or testing for one multiple, changes which blocks are counted.

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

Exams that ask this topic