Question
You are planning the first months of a side business. You are given the projected net cash flow for each month in order (income minus expenses; may be negative). You will fund the business with a one-time starting balance before month one, and the running balance must never drop below zero after any month. Return the smallest non-negative starting balance that keeps the plan safe. An empty plan needs 0. For example, [-5, 3, -2, 4] needs 5.
min_starting_balance(cashflows: list[int]) → int[[-5,3,-2,4]]out5[[4,-6,3,-2]]out2State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.