package leetcode;

/**
 * https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/
 */
public class Problem1413 {
    public int minStartValue(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1413 prob = new Problem1413();
        System.out.println(prob.minStartValue(new int[]{-3,2,-3,4,2})); // 5
        System.out.println(prob.minStartValue(new int[]{1,2})); // 1
        System.out.println(prob.minStartValue(new int[]{1,-2,-3})); // 5
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/
 */
public class Problem1413 {
    public int minStartValue(int[] nums) {
        int sum = 0;
        int min = Integer.MAX_VALUE;
        for (int num : nums) {
            sum += num;
            min = Math.min(min, sum);
        }
        int answer = 1 - min;
        return answer <= 0 ? 1 : answer;
    }
}

Solve problem 1413