Data Structures & AlgorithmsModerate

Choose two NON-OVERLAPPING non-empty contiguous subarrays of 2 -3 5 1 -2 4 -1 3, one entirely to the left of the other. What is the maximum possible total of their sums?

  1. A. 20
  2. B. 10
  3. C. 12
  4. D. 7

Correct answer: C. 12

Split the array at some point and take the best subarray on each side; the best split gives the answer. Doubling the global best ignores the non-overlap rule, and a single subarray ignores the second block.

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

Exams that ask this topic