Tank overflow first day

Write codeEasy10 min

Your task

A rainwater tank starts empty and has a capacity in liters. You are given the forecast daily inflow, in liters per day, as a list of integers (a maintenance drain may make a day negative). Return the index of the first day on which the cumulative total strictly exceeds the capacity, or -1 if that never happens. Example: inflows = [300, 200, 400], capacity = 800 gives 2, because the running totals are 300, 500, then 900.

Examples

overflow_day(inflows: list[int], capacity: int) -> int
Example 1
Inputoverflow_day([300, 200, 400], 800)
Output2