Class Solution
java.lang.Object
g1101_1200.s1186_maximum_subarray_sum_with_one_deletion.Solution
1186 - Maximum Subarray Sum with One Deletion.<p>Medium</p>
<p>Given an array of integers, return the maximum sum for a <strong>non-empty</strong> subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible.</p>
<p>Note that the subarray needs to be <strong>non-empty</strong> after deleting one element.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [1,-2,0,3]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [1,-2,-2,3]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> We just choose [3] and it’s the maximum sum.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> arr = [-1,-1,-1,-1]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> The final subarray needs to be non-empty. You can’t choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= arr.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup> <= arr[i] <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumSum
public int maximumSum(int[] arr)
-