java.lang.Object
g1001_1100.s1043_partition_array_for_maximum_sum.Solution

public class Solution extends Object
1043 - Partition Array for Maximum Sum.<p>Medium</p> <p>Given an integer array <code>arr</code>, partition the array into (contiguous) subarrays of length <strong>at most</strong> <code>k</code>. After partitioning, each subarray has their values changed to become the maximum value of that subarray.</p> <p>Return <em>the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a <strong>32-bit</strong> integer.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> arr = [1,15,7,9,2,5,10], k = 3</p> <p><strong>Output:</strong> 84</p> <p><strong>Explanation:</strong> arr becomes [15,15,15,9,10,10,10]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4</p> <p><strong>Output:</strong> 83</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> arr = [1], k = 1</p> <p><strong>Output:</strong> 1</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= arr.length <= 500</code></li> <li><code>0 <= arr[i] <= 10<sup>9</sup></code></li> <li><code>1 <= k <= arr.length</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxSumAfterPartitioning

      public int maxSumAfterPartitioning(int[] arr, int k)