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?
- A. 7
- B. 36
- C. 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Choose two disjoint contiguous windows of length exactly 2 in [1, 2, 9, 4, 5, 1, 8, 3] (the windows may not share an index). What is the…
- What is the maximum product over all non-empty contiguous subarrays of [2, 3, -2, 4, -1, -5, 0, 2]?
- How many distinct values in [3, 3, 4, 2, 4, 4, 2, 4, 4] occur strictly more than n/3 times (n = 9)?
- How many non-empty subarrays of [1, 2, 1, 2, 3, 3, 1] contain every value an even number of times?
- Flowers bloom on the days [1, 10, 3, 10, 2]. You need to make 2 bouquets, each from 2 adjacent bloomed flowers (flowers may only be used…
- In the binary array [1, 1, 0, 1, 1, 1, 0, 1, 1], you may flip exactly one 0 to 1 (or flip none). What is the length of the longest run of…