PIXELBANKv9.1.0
Menu

Problem Statement

Given an availability SLO and observed request counts, compute how much of the error budget remains.

Background

For a target availability slo (e.g. 0.999) over total requests, the allowed failures (error budget) is (1 - slo) * total. With bad observed failures, the fraction of budget remaining is (budget - bad) / budget, clamped to [−∞, 1] but reported down to negative if exhausted. If the budget is 0 (slo == 1), remaining is 1.0 when bad == 0 else 0.0.

Your Task

def error_budget_remaining(slo, total, bad):

Return the fraction of error budget remaining, rounded to 4 decimals (may be negative).

Input Format

  • slo (float in (0,1]), total (int), bad (int).

Output Format

  • A float rounded to 4 decimals.

Sample

print(error_budget_remaining(0.99, 1000, 4))

Output:

0.6

Example:

Input:
print(error_budget_remaining(0.99, 1000, 4))
Output:
0.6
Reasoning:
  • Calculate the total error budget allowed by the SLO: with a target availability of 0.990.99 and 10001000 total requests, the allowed failures are (1−0.99)×1000=10(1 - 0.99) \times 1000 = 10.
  • Determine the remaining budget by subtracting the observed failures from the total budget: 10−4=610 - 4 = 6.
  • Compute the fraction of the budget remaining by dividing the remaining budget by the total budget: 6/10=0.66 / 10 = 0.6.
  • Round the result to 4 decimal places as required: 0.60.6 remains 0.60.6.
  • The final output is 0.6

Constraints:

  • budget = (1 - slo) * total.
  • remaining = (budget - bad) / budget; if budget == 0, return 1.0 (bad==0) else 0.0.
  • Round to 4 decimals; may be negative if overspent.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.