1031. Maximum Sum of Two Non-Overlapping Subarrays Medium
1/**
2 * [1031] Maximum Sum of Two Non-Overlapping Subarrays
3 *
4 * Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths firstLen and secondLen.
5 * The array with length firstLen could occur before or after the array with length secondLen, but they have to be non-overlapping.
6 * A subarray is a contiguous part of an array.
7 *
8 * Example 1:
9 *
10 * Input: nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2
11 * Output: 20
12 * Explanation: One choice of subarrays is [9] with length 1, and [6,5] with length 2.
13 *
14 * Example 2:
15 *
16 * Input: nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2
17 * Output: 29
18 * Explanation: One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.
19 *
20 * Example 3:
21 *
22 * Input: nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3
23 * Output: 31
24 * Explanation: One choice of subarrays is [5,6,0,9] with length 4, and [0,3,8] with length 3.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= firstLen, secondLen <= 1000
30 * 2 <= firstLen + secondLen <= 1000
31 * firstLen + secondLen <= nums.length <= 1000
32 * 0 <= nums[i] <= 1000
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays/
38// discuss: https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn max_sum_two_no_overlap(nums: Vec<i32>, first_len: i32, second_len: i32) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_1031() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.