Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

What is the maximum sum of a contiguous subarray of [4, -3, 5, 2, -7, 6, 1, 3] whose length is ODD?

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

Correct answer: B. 10

Fix the parity of the length and combine prefix sums of the matching parity: the best odd-length window ends at j and starts at an index i with j − i even. Plain Kadane ignores the length parity and can return an even-length answer.

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

Exams that ask this topic