3788. Maximum Score of a Split Medium

@problem@discussion
#Array#Prefix Sum



1/**
2 * [3788] Maximum Score of a Split
3 *
4 * You are given an integer array nums of length n.
5 * Choose an index i such that 0 <= i < n - 1.
6 * For a chosen split index i:
7 * 
8 * 	Let prefixSum(i) be the sum of nums[0] + nums[1] + ... + nums[i].
9 * 	Let suffixMin(i) be the minimum value among nums[i + 1], nums[i + 2], ..., nums[n - 1].
10 * 
11 * The score of a split at index i is defined as:
12 * score(i) = prefixSum(i) - suffixMin(i)
13 * Return an integer denoting the maximum score over all valid split indices.
14 *  
15 * <strong class="example">Example 1:
16 * <div class="example-block">
17 * Input: <span class="example-io">nums = [10,-1,3,-4,-5]</span>
18 * Output: <span class="example-io">17</span>
19 * Explanation:
20 * The optimal split is at i = 2, score(2) = prefixSum(2) - suffixMin(2) = (10 + (-1) + 3) - (-5) = 17.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [-7,-5,3]</span>
25 * Output: <span class="example-io">-2</span>
26 * Explanation:
27 * The optimal split is at i = 0, score(0) = prefixSum(0) - suffixMin(0) = (-7) - (-5) = -2.
28 * </div>
29 * <strong class="example">Example 3:
30 * <div class="example-block">
31 * Input: <span class="example-io">nums = [1,1]</span>
32 * Output: <span class="example-io">0</span>
33 * Explanation:
34 * The only valid split is at i = 0, score(0) = prefixSum(0) - suffixMin(0) = 1 - 1 = 0.
35 * </div>
36 *  
37 * Constraints:
38 * 
39 * 	2 <= nums.length <= 10^5
40 * 	-10^9​​​​​​​ <= nums[i] <= 10^9
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/maximum-score-of-a-split/
46// discuss: https://leetcode.com/problems/maximum-score-of-a-split/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn maximum_score(nums: Vec<i32>) -> i64 {
52        
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_3788() {
64    }
65}
66

Back
© 2026 bowen.ge All Rights Reserved.