Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The array [3, 7, 1, 9] is used to create all non-empty contiguous subarrays. How many of them have an odd sum?

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

Correct answer: D. 6

All values are odd, so a sum is odd iff the length is odd: 4 subarrays of length 1 and 2 of length 3 give 6. 10 counts all subarrays, 4 counts the even sums, and 2 counts only length 3.

More Coding Interview Problems questions

Exams that ask this topic