Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3473 - Sum of K Subarrays With Length at Least M.

    Medium

    You are given an integer array nums and two integers, k and m.

    Return the maximum sum of k non-overlapping subarrays of nums, where each subarray has a length of at least m.

    Example 1:

    Input: nums = 1,2,-1,3,3,4, k = 2, m = 2

    Output: 13

    Explanation:

    The optimal choice is:

    • Subarray nums[3..5] with sum 3 + 3 + 4 = 10 (length is 3 >= m).

    • Subarray nums[0..1] with sum 1 + 2 = 3 (length is 2 >= m).

    The total sum is 10 + 3 = 13.

    Example 2:

    Input: nums = -10,3,-1,-2, k = 4, m = 1

    Output: \-10

    Explanation:

    The optimal choice is choosing each element as a subarray. The output is (-10) + 3 + (-1) + (-2) = -10.

    Constraints:

    • 1 <= nums.length <= 2000

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

    • 1 &lt;= k &lt;= floor(nums.length / m)

    • 1 &lt;= m &lt;= 3

    • 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 Integer maxSum(IntArray nums, Integer k, Integer m)
      • Methods inherited from class java.lang.Object

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