Data Structures & AlgorithmsModerate

How many contiguous subarrays of 5 2 7 1 8 3 6 4 have an ODD length and a sum divisible by 7?

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

Correct answer: B. 3

Both conditions apply to the same block: the length parity and the sum residue mod 7. Dropping the parity test, reversing it, or negating the residue test each counts a different family.

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

Exams that ask this topic