Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

What is the length of the longest contiguous subarray of [1, 2, 4, 3, 6, 8, 5, 7] whose sum is even?

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

Correct answer: D. 8

Only prefix-sum parity matters, and the total 1 + 2 + 4 + 3 + 6 + 8 + 5 + 7 = 36 is even, so the whole array (8) qualifies. Assuming the full array fails gives 7, 36 is the sum rather than a length, and 4 just counts the even elements.

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

Exams that ask this topic