Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

How many contiguous subarrays of [2, 4, 6, 3, 9] have an odd sum?

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

Correct answer: D. 5

Only subarrays containing an odd number of odd elements have odd sums; the odd values here are 3 and 9, so track the parity of prefix sums.

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

Exams that ask this topic