Class Solution
java.lang.Object
g1001_1100.s1031_maximum_sum_of_two_non_overlapping_subarrays.Solution
1031 - Maximum Sum of Two Non-Overlapping Subarrays.<p>Medium</p>
<p>Given an integer array <code>nums</code> and two integers <code>firstLen</code> and <code>secondLen</code>, return <em>the maximum sum of elements in two non-overlapping <strong>subarrays</strong> with lengths</em> <code>firstLen</code> <em>and</em> <code>secondLen</code>.</p>
<p>The array with length <code>firstLen</code> could occur before or after the array with length <code>secondLen</code>, but they have to be non-overlapping.</p>
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2</p>
<p><strong>Output:</strong> 20</p>
<p><strong>Explanation:</strong> One choice of subarrays is [9] with length 1, and [6,5] with length 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2</p>
<p><strong>Output:</strong> 29</p>
<p><strong>Explanation:</strong> One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3</p>
<p><strong>Output:</strong> 31</p>
<p><strong>Explanation:</strong> One choice of subarrays is [5,6,0,9] with length 4, and [3,8] with length 3.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= firstLen, secondLen <= 1000</code></li>
<li><code>2 <= firstLen + secondLen <= 1000</code></li>
<li><code>firstLen + secondLen <= nums.length <= 1000</code></li>
<li><code>0 <= nums[i] <= 1000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxSumTwoNoOverlap
public int maxSumTwoNoOverlap(int[] nums, int f, int s)
-