1043. Partition Array for Maximum Sum Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [1043] Partition Array for Maximum Sum
3 *
4 * 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.
5 * Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.
6 *  
7 * Example 1:
8 * 
9 * Input: arr = [1,15,7,9,2,5,10], k = 3
10 * Output: 84
11 * Explanation: arr becomes [15,15,15,9,10,10,10]
12 * 
13 * Example 2:
14 * 
15 * Input: arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4
16 * Output: 83
17 * 
18 * Example 3:
19 * 
20 * Input: arr = [1], k = 1
21 * Output: 1
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	1 <= arr.length <= 500
27 * 	0 <= arr[i] <= 10^9
28 * 	1 <= k <= arr.length
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/partition-array-for-maximum-sum/
34// discuss: https://leetcode.com/problems/partition-array-for-maximum-sum/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn max_sum_after_partitioning(arr: Vec<i32>, k: i32) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_1043() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.