Code Room
CodingMediumcod-g1150
Subject Networking protocolsLevel Mid–Senior~22 minCommon in Networking & APIs interviewsIndustries Software development, Technology

Question

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.

Implement
retry_budget(requests: list[str], ratio: float, min_per_sec: int) → int
Examples
in[["req","req","req","req","req","retry","retry"],0.2,0]out1
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.

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.

Run or narrate your approach, then ask the coach.