Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

How many contiguous subarrays of [2, 3, 5, 4, 7, 6, 9] contain EXACTLY two odd numbers?

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

Correct answer: C. 8

Exactly-k counting: count subarrays with at most two odd numbers minus those with at most one, by a sliding window over the odd count. Counting windows that contain at least two odds overcounts.

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

Exams that ask this topic