Partition Array for Maximum Sum

Given an integer array arr, partition the array into contiguous subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray. Return the largest sum of the given array after partitioning.

Constraints

  • 1 <= arr.length <= 500
  • 0 <= arr[i] <= 10^9
  • 1 <= k <= arr.length
Saving… · 3 lines
class Solution:
def partitionArrayForMaxSum(self, arr: List[int], k: int) -> int:
Console

Click Run to execute sample tests.