Intermediate
Find the stage furthest over budget
Write percentile(values, pct) using the nearest-rank rule: sort the values and return the one at position ceil(pct * n / 100) (counting from 1). Use whole-number arithmetic: (pct * n + 99) // 100.
Write worst_stage(samples, budgets). samples maps a stage name to a list of milliseconds, budgets maps it to its p95 budget. Return the name of the stage whose p95 is furthest over its budget, or None when no stage is over.
What Check tests
- p50 of ten values
- p95 of ten values is the largest
- p95 of twenty values is the 19th
- Finds the stage furthest over
- Returns None when nothing is over
- A stage exactly at budget is not over
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.