Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

For [1, -2, 3, 4, -1, 5, -6, 2], you may delete at most one element before taking a maximum sum over non-empty contiguous subarrays. What is the largest possible sum?

  1. A. 14
  2. B. 11
  3. C. 9
  4. D. 13

Correct answer: D. 13

Track the best subarray ending here with and without one deletion (a two-state Kadane). Deleting a negative value that separates two good runs merges them, and a brute force over single deletions confirms the maximum.

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

Exams that ask this topic