689. Maximum Sum of 3 Non-Overlapping Subarrays Hard

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [689] Maximum Sum of 3 Non-Overlapping Subarrays
3 *
4 * Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them.
5 * Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,2,1,2,6,7,5,1], k = 2
10 * Output: [0,3,5]
11 * Explanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].
12 * We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.
13 * 
14 * Example 2:
15 * 
16 * Input: nums = [1,2,1,2,1,2,1,2,1], k = 2
17 * Output: [0,2,4]
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	1 <= nums.length <= 2 * 10^4
23 * 	1 <= nums[i] < 2^16
24 * 	1 <= k <= floor(nums.length / 3)
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/
30// discuss: https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn max_sum_of_three_subarrays(nums: Vec<i32>, k: i32) -> Vec<i32> {
36        vec![]
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_689() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.