Data Structures & AlgorithmsHard

What is the maximum sum of a contiguous subarray of 3 5 2 7 9 1 4 11 in which every element is ODD?

  1. A. 42
  2. B. 19
  3. C. 17
  4. D. 18

Correct answer: C. 17

Split the array at even values; the best all-odd block lies inside one of the resulting maximal odd runs. Using the unconstrained maximum, or requiring at least one odd element, admits blocks with even values.

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

Exams that ask this topic