Loading...
You are given an integer array nums and two integers k and l.
Choose two contiguous fragments of nums: one of length k and one of length l. The two fragments may overlap (they may even occupy the same positions).
The chosen fragments determine a total:
Return the maximum total over all placements of the two fragments.
Input: nums = [1, 3, -4, 2, -2], k = 3, l = 2
Output: 10
Explanation: Take the length-3 fragment at indices 0-2 and the length-2 fragment
at indices 2-3. Index 2 is covered by both fragments, so -4 contributes +4.
Total = 1 + 3 + 4 + 2 = 10.
Input: nums = [-3], k = 1, l = 1
Output: 3
Explanation: Both fragments must cover the single element, which is therefore
negated: -(-3) = 3.
nums.length ≤105nums[i] ≤1000nums.lengthClick "Run" to test with sample cases or "Submit" to run all tests.