1413. Minimum Value to Get Positive Step by Step Sum Easy

@problem@discussion
#Array#Prefix Sum



1/**
2 * [1413] Minimum Value to Get Positive Step by Step Sum
3 *
4 * Given an array of integers nums, you start with an initial positive value startValue.
5 * In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).
6 * Return the minimum positive value of startValue such that the step by step sum is never less than 1.
7 *  
8 * Example 1:
9 * 
10 * Input: nums = [-3,2,-3,4,2]
11 * Output: 5
12 * Explanation: If you choose startValue = 4, in the third iteration your step by step sum is less than 1.
13 * step by step sum
14 * startValue = 4 | startValue = 5 | nums
15 *   (4 -3 ) = 1  | (5 -3 ) = 2    |  -3
16 *   (1 +2 ) = 3  | (2 +2 ) = 4    |   2
17 *   (3 -3 ) = 0  | (4 -3 ) = 1    |  -3
18 *   (0 +4 ) = 4  | (1 +4 ) = 5    |   4
19 *   (4 +2 ) = 6  | (5 +2 ) = 7    |   2
20 * 
21 * Example 2:
22 * 
23 * Input: nums = [1,2]
24 * Output: 1
25 * Explanation: Minimum start value should be positive. 
26 * 
27 * Example 3:
28 * 
29 * Input: nums = [1,-2,-3]
30 * Output: 5
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	1 <= nums.length <= 100
36 * 	-100 <= nums[i] <= 100
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/
42// discuss: https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn min_start_value(nums: Vec<i32>) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_1413() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.