MEDIUMasked at 1 company

Maximum Subarray Sum with One Deletion

A medium-tier problem at 45% community acceptance, tagged with Array, Dynamic Programming. Reported in interviews at Two Sigma and 0 others.

Founder's read

You're staring at an array and need to find the maximum sum subarray, but with a twist: you're allowed to delete exactly one element to potentially boost the sum. Two Sigma asks this problem, and it's where the obvious greedy approach breaks down fast. You can't just delete the smallest element or skip one contraction and call it solved. The real move is tracking two states simultaneously as you iterate: the max sum if you haven't deleted yet, and the max sum if you already have. If this pattern hits your live OA and you freeze on the state machine, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
45%

Companies that ask "Maximum Subarray Sum with One Deletion"

If this hits your live OA

Maximum Subarray Sum with One Deletion is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

This is a dynamic programming problem disguised as a greedy one. Most candidates try Kadane's algorithm and then manually delete elements, but that's O(n^2) and fragile. The trick is maintaining two DP arrays as you scan left to right: one tracking the best subarray ending at index i without deletion, another tracking the best subarray ending at i with exactly one deletion used. At each step, you either extend the previous subarray, start fresh, or use your deletion to skip an element and bridge the gap. The edge case that kills submissions is handling the boundary: you can delete an element from the middle of a subarray and reconnect, or delete a single-element subarray and start fresh. Common pitfall: confusing 'one deletion allowed' with 'at most one deletion', this problem forces you to make a choice. When you practice, force yourself to implement both states cleanly before moving to the next problem.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Maximum Subarray Sum with One Deletion recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Subarray Sum with One Deletion interview FAQ

Is this really just Kadane's algorithm plus deletion logic?+

No. Kadane alone doesn't account for using your deletion optimally. You need DP state tracking: track max sum without deletion, then max sum with deletion, updating both in parallel as you iterate. The deletion choice cascades forward, so you can't retrofit it after computing Kadane.

Two Sigma asks this. How often does it show up elsewhere?+

It's reported from one major company in the data. Medium difficulty and 45% acceptance rate suggest it's a strong filter question for technical interviews, though not in the ultra-high-volume rotation of easier DP problems.

What's the difference between 'one deletion' and 'at most one'?+

One deletion means you must delete exactly one element to qualify. At most one means you can skip deletion if no deletion helps. This problem enforces the exact-one constraint, which forces you to either delete from a subarray or delete a standalone element.

How does this relate to Dynamic Programming beyond just DP tag?+

It requires subproblem overlap and optimal substructure. Your choice to delete at position i affects the best sum reachable at i+1. You build the solution bottom-up, storing two values per index, which is classic DP state compression.

What kills most submissions on this problem?+

Forgetting to handle the case where you delete an internal element and reconnect two subarrays, or initializing state incorrectly for the first few elements. Also, confusing deletion with starting fresh. Practice with edge cases: single element, all negatives, deletion must happen in middle.

Want the actual problem statement? View "Maximum Subarray Sum with One Deletion" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.