Z19
Maximum Sum of Two Non-Overlapping Subarrays
Problem Statement & Objective
Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays of lengths firstLen and secondLen.
Function Signature (Python)
max_sum_two_non_overlapping(nums: list[int], l1: int, l2: int) -> intInput & Output Contract
Output Rule:Maximum integer sum of the two subarrays.
System Constraints
1 <= firstLen, secondLen <= 1000
2 <= firstLen + secondLen <= nums.length <= 1000
0 <= nums[i] <= 1000Example Execution Walkthrough
nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2
result: 20 (subarrays [9] and [5, 6] or [9] and [1, 9]...)Example Test Scenarios (3)
Example 1
Input:
[[0,6,5,2,2,5,1,9,4],1,2]Expected Output:
20Example 2: [3,8,1] ve [8,9]
Input:
[[3,8,1,3,2,1,8,9,0],3,2]Expected Output:
29Example 3
Input:
[[2,1,5,6,0,9,5,0,3,8],4,3]Expected Output:
31