Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3430 - Maximum and Minimum Sums of at Most Size K Subarrays.

    Hard

    You are given an integer array nums and a positive integer k. Return the sum of the maximum and minimum elements of all non-empty subarrays with at most k elements.

    Example 1:

    Input: nums = 1,2,3, k = 2

    Output: 20

    Explanation:

    The subarrays of nums with 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 nums with at most 2 elements are:

    The output would be -6.

    Constraints:

    • 1 <= nums.length <= 80000

    • 1 <= k <= nums.length

    • <code>-10<sup>6</sup><= numsi<= 10<sup>6</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Long minMaxSubarraySum(IntArray nums, Integer k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait