FastPrepMaximum Subarray Sum with One Deletion
Problems/Maximum Subarray Sum with One Deletion

Maximum Subarray Sum with One Deletion

Oracle logoOracle● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: An experienced engineer described an onsite with an Oracle cloud infrastructure team. The first round was given only as a LeetCode problem number, written in number slang; decoded, it is problem 1186, the largest subarray sum when one element may be removed. The report has no statement, examples, limits or follow-ups.

Practice choices: the task uses the standard public definition of that problem: the chosen subarray is contiguous and non-empty, at most one of its elements may be deleted, and at least one element must remain. The limits and all examples are ours.

The judged task matches the report at about 90%.

You are given an integer array arr. Choose one non-empty contiguous subarray. You may then delete at most one element from the chosen subarray, but at least one element must remain after the deletion.

Return the largest possible sum of the elements that remain.

Function

maximumSum(arr: int[]) → int

Examples

Example 1

arr = [3,-4,5,1]return = 9

Take the whole array and delete -4. The remaining elements 3, 5, 1 add up to 9. Without a deletion the best is 5 + 1 = 6.

Example 2

arr = [2,-1,-6,4]return = 5

Take the whole array and delete -6: 2 + (-1) + 4 = 5. Only one element may be deleted, so -1 must stay. Any choice that avoids -6 without deleting it lies inside [2, -1] or [4]; the best of those is 4, which is smaller.

Example 3

arr = [-5,-2,-8]return = -2

Every element is negative. At least one element must remain, so the best choice is the single element -2, with no deletion.

Constraints

  • 1 <= arr.length <= 2 * 104
  • -104 <= arr[i] <= 104

More Oracle problems

  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
  • Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public int maximumSum(int[] arr) {
        // Write your code here.
    }
}
Checking account…