Data Structures & AlgorithmsVery hard

How many contiguous subarrays of length exactly 2 in 2 6 3 5 8 1 4 7 have a sum that is a multiple of 4 OR a product that is a multiple of 4?

  1. A. 1
  2. B. 6
  3. C. 2
  4. D. 5

Correct answer: B. 6

The OR asks for pairs satisfying at least one condition, so inclusion-exclusion is needed when both hold. Counting only the sum test, only the product test, or requiring both each give a different answer.

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

Exams that ask this topic