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?
- A. 14
- B. 11
- C. 9
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the sum of i j over all pairs 1 <= i < j <= 6?
- How many index triples i < j < k in [2, 3, 5, 7, 8] satisfy a[k] - a[i] <= 4?
- Swap the first two elements of [2, 4, 1, 3, 5], then count the inversions of the new array. What is the count?
- Closed intervals [1,3], [3,5], [5,7], [2,4] must be thinned so that no two remaining intervals share even a single point. What is the…
- How many ordered pairs (a, b) with 1 <= a, b <= 6 have a^2 + b^2 a perfect square?
- Apply the operations push 3, push 5, pop, push 7, push 2, pop, pop to an initially empty stack. What is the sum of the values remaining on…