Trains the technique from
LeetCode 1413Minimum Value to Get Positive Step by Step SumThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An account is opened holding some whole amount, and then the entries of changes are applied to the balance one at a time, in the order given.
Return the smallest opening amount, itself at least 1, that leaves the balance at 1 or more after every entry has been applied.
Example 1
The running totals of the entries are -4, -1, -5, 0 and 3, so the deepest the balance ever sits below its opening amount is five. Opening with six leaves the balance at one at that lowest point, and opening with five would leave it at nothing.
Example 2
Both entries add, so the balance only climbs and the smallest allowed opening amount already works.
Example 3
The running totals are 2, -1 and -5, and the last of those is the deepest, so the opening amount has to cover five and leave one over.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def min_start_value(changes: list[int]) -> int:public int minStartValue(int[] changes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.