Count negative balance months

Write codeEasy10 min

Your task

A project budget starts at zero. Each month contributes a signed net amount: income minus spending. Given the list of monthly net amounts in order, return how many months end with the cumulative balance strictly below zero. Example: nets = [100, -250, 80, 90] gives 2, the running balances are 100, -150, -70, 20, and two of them are negative.

Examples

months_in_deficit(nets: list[int]) -> int
Example 1
Inputmonths_in_deficit([100, -250, 80, 90])
Output2