Data Structures & AlgorithmsHard

From the array 3 -1 8 2 -4 6 5 you may take exactly 3 elements, each taken from the LEFT end or from the RIGHT end of what remains. What is the maximum possible total?

  1. A. 10
  2. B. 7
  3. C. 6
  4. D. 14

Correct answer: D. 14

Any choice is some prefix of length i plus a suffix of length k−i, so enumerate the split i from 0 to k. Taking only from one end, or subtracting the maximum element, does not cover all splits.

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

Exams that ask this topic