Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT

You may delete one contiguous block from [4, -9, 3, 5, -2, 7, -8, 6] (possibly empty block) and keep the prefix before it and the suffix after it. What is the maximum sum of the remaining elements?

  1. A. 15
  2. B. 7
  3. C. 10
  4. D. 16

Correct answer: A. 15

Delete the best contiguous block: the answer is the largest sum of a prefix plus a suffix that do not overlap, which is the total minus the most negative contiguous block. Keeping only a prefix or only a suffix is a special case.

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

Exams that ask this topic