mediumArrayDynamic ProgrammingPrefix Sum 0 views

Sum of K Subarrays With Length at Least M

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

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.

Sum of K Subarrays With Length at Least M diagram

Example 1

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

Output: 13

Explanation: The optimal choice is: 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
  • -10^4 <= nums[i] <= 10^4
  • 1 <= k <= floor(nums.length / m)
  • 1 <= m <= 3

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.