Class Solution
-
- All Implemented Interfaces:
public final class Solution3430 - Maximum and Minimum Sums of at Most Size K Subarrays.
Hard
You are given an integer array
numsand a positive integerk. Return the sum of the maximum and minimum elements of all non-empty subarrays with at mostkelements.Example 1:
Input: nums = 1,2,3, k = 2
Output: 20
Explanation:
The subarrays of
numswith at most 2 elements are:The output would be 20.
Example 2:
Input: nums = 1,-3,1, k = 2
Output: \-6
Explanation:
The subarrays of
numswith at most 2 elements are:The output would be -6.
Constraints:
1 <= nums.length <= 800001 <= k <= nums.length<code>-10<sup>6</sup><= numsi<= 10<sup>6</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final LongminMaxSubarraySum(IntArray nums, Integer k)-
-
Method Detail
-
minMaxSubarraySum
final Long minMaxSubarraySum(IntArray nums, Integer k)
-
-
-
-