java.lang.Object
g1401_1500.s1413_minimum_value_to_get_positive_step_by_step_sum.Solution

public class Solution extends Object
1413 - Minimum Value to Get Positive Step by Step Sum.<p>Easy</p> <p>Given an array of integers <code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em>_._</p> <p>In each iteration, you calculate the step by step sum of <em>startValue</em> plus elements in <code>nums</code> (from left to right).</p> <p>Return the minimum <strong>positive</strong> value of <em>startValue</em> such that the step by step sum is never less than 1.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [-3,2,-3,4,2]</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> If you choose startValue = 4, in the third iteration your step by step sum is less than 1.</p> <p><strong>step by step sum</strong></p> <p><strong>startValue = 4 | startValue = 5 | nums</strong></p> <p>(4 <strong>-3</strong> ) = 1 | (5 <strong>-3</strong> ) = 2 | -3</p> <p>(1 <strong>+2</strong> ) = 3 | (2 <strong>+2</strong> ) = 4 | 2</p> <p>(3 <strong>-3</strong> ) = 0 | (4 <strong>-3</strong> ) = 1 | -3</p> <p>(0 <strong>+4</strong> ) = 4 | (1 <strong>+4</strong> ) = 5 | 4</p> <p>(4 <strong>+2</strong> ) = 6 | (5 <strong>+2</strong> ) = 7 | 2</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,2]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> Minimum start value should be positive.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,-2,-3]</p> <p><strong>Output:</strong> 5</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 100</code></li> <li><code>-100 <= nums[i] <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minStartValue

      public int minStartValue(int[] nums)