Class Solution
java.lang.Object
g1601_1700.s1695_maximum_erasure_value.Solution
1695 - Maximum Erasure Value.<p>Medium</p>
<p>You are given an array of positive integers <code>nums</code> and want to erase a subarray containing <strong>unique elements</strong>. The <strong>score</strong> you get by erasing the subarray is equal to the <strong>sum</strong> of its elements.</p>
<p>Return <em>the <strong>maximum score</strong> you can get by erasing <strong>exactly one</strong> subarray.</em></p>
<p>An array <code>b</code> is called to be a subarray of <code>a</code> if it forms a contiguous subsequence of <code>a</code>, that is, if it is equal to <code>a[l],a[l+1],...,a[r]</code> for some <code>(l,r)</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [4,2,4,5,6]</p>
<p><strong>Output:</strong> 17</p>
<p><strong>Explanation:</strong> The optimal subarray here is [2,4,5,6].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [5,2,1,2,5,2,1,2,5]</p>
<p><strong>Output:</strong> 8</p>
<p><strong>Explanation:</strong> The optimal subarray here is [5,2,1] or [1,2,5].</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumUniqueSubarray
public int maximumUniqueSubarray(int[] nums)
-