Data Structures & AlgorithmsModerate

How many contiguous subarrays of 2 3 4 1 6 9 have a product divisible by 6?

  1. A. 15
  2. B. 18
  3. C. 17
  4. D. 3

Correct answer: A. 15

Divisibility by 6 needs a factor of 2 and a factor of 3, which may come from different elements of the block. Testing only one prime, or only the exact value 6, measures a weaker or narrower condition.

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

Exams that ask this topic