Data Structures & AlgorithmsHard

How many contiguous subarrays of 1 3 2 4 5 3 1 6 have a sum divisible by 4 AND an odd length?

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

Correct answer: B. 3

Both conditions must hold on the same subarray: the sum test uses the residue mod 4 and the length test uses parity. Dropping the length test, reversing the parity, or testing evenness of the sum instead changes the total.

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

Exams that ask this topic