Minimum Value to Get Positive Step by Step Sum
Problem Description
Given an array of integers nums, find the minimum positive value of startValue such that the step-by-step sum (startValue + prefix sum at each step) is never less than 1.
In the D.E. Shaw round (SMTS April 2025), this was the warm-up problem — solve it quickly and pivot to design/React follow-ups.
Pattern: Find the minimum prefix sum across all positions. The answer is max(1, 1 - minPrefixSum).
Example 1:
Input: nums = [-3,2,-3,4,2]
Output: 5
Explanation: startValue=5: 5-3=2, 2+2=4, 4-3=1, 1+4=5, 5+2=7. All ≥ 1.
Example 2:
Input: nums = [1,2]
Output: 1
Example 3:
Input: nums = [1,-2,-3]
Output: 5
Example Test Cases
Example 1
Input: [[-3,2,-3,4,2]]
Expected: 5
Example 2
Input: [[1,2]]
Expected: 1
Example 3
Input: [[1,-2,-3]]
Expected: 5
Run your code to see the results