Maximum Subarray Sum with One Deletion
Problem Statement
You are given an integer array arr. You may delete at most one element. When an element is deleted, its two neighbours touch, so a run can now cross the gap.
After the optional deletion, find a non-empty contiguous subarray with the largest sum, and return that sum. You must keep at least one element, so a result with nothing left is not allowed.
An integer array arr of length n.
One number: the largest sum of a non-empty subarray, after deleting at most one element.
Delete the -2. The array becomes [1, 0, 3], which sums to 4.
Without a deletion, the best run is [3] = 3. Deleting one -2 leaves [1, -2, 3], whose best run is still 3, so deleting does not help.
Deleting is allowed, but one element must stay. The best choice is a single -1.
- • 1 ≤ arr.length ≤ 10^5
- • −10^4 ≤ arr[i] ≤ 10^4
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Try deleting each element (or none), run Kadane on the rest, keep the best
Precompute left[i] (run ending at i) and right[i] (run starting at i); answer = left[i−1] + right[i+1]
One pass with keep (no deletion yet) and del (one deleted); update both
There are only n + 1 choices: delete nothing, or delete element d for each d. For each choice, run Maximum subarray on what is left, and keep the largest answer.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like DP — Kadane / Subarray translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.