Code RoomMinimum starting balance
EasyPrep Room Coding #687

Minimum starting balance

CodingAlgorithms & data structuresEntry–Mid~10 min

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.

Implement
min_starting_balance(cashflows: list[int]) → int
Examples
in[[-5,3,-2,4]]out5
in[[4,-6,3,-2]]out2
What a strong answer looks like

State 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.

0:00 of about 10 min
InputExpectedGot
[[-5,3,-2,4]]5not run yetsample
[[4,-6,3,-2]]2not run yetsample