Data Structures & AlgorithmsVery hard

How many contiguous subarrays of 2 3 4 5 6 7 8 contain EXACTLY two even values and have an ODD length?

  1. A. 8
  2. B. 7
  3. C. 4
  4. D. 5

Correct answer: C. 4

Count the even values in each block and then apply the parity of its length; both must hold together. Dropping the length test, relaxing to at least two, or flipping the parity each change the set.

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

Exams that ask this topic