Retry budget tokens

Write codeMedium22 minGoogle style

Your task

Compute how many retries a client-side retry budget permits. Maintain a token balance starting at min_budget. Process an ordered list of events: a 'req' event adds 'ratio' tokens to the balance (ratio is the retries-per-request allowance, e.g. 0.2); a 'retry' event is allowed only if the balance is >= 1.0, in which case it consumes 1.0 token and counts as allowed, otherwise it is denied (balance unchanged). Return the total number of retries that were allowed. ratio is a non-negative float; min_budget is a non-negative int.

Examples

retry_budget(requests: list[str], ratio: float, min_per_sec: int) -> int
Example 1
Inputretry_budget(["req", "req", "req", "req", "req", "retry", "retry"], 0.2, 0)
Output1