Data Structures & AlgorithmsHard

What is the length of the longest contiguous subarray of 4 6 3 8 10 12 5 2 4 in which EVERY element is even and whose length is odd?

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

Correct answer: A. 3

Find the maximal runs of even values, then take the largest odd length that fits inside one run. Ignoring the length parity gives the even-only maximum, and allowing one odd element changes the set.

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

Exams that ask this topic