Command Palette

Search for a command to run...

Hectal
Phase 11: RAG in Production
RAG and Vector Search · Exercise 3 of 5 PreviousNext
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

  1. p50 of ten values
  2. p95 of ten values is the largest
  3. p95 of twenty values is the 19th
  4. Finds the stage furthest over
  5. Returns None when nothing is over
  6. 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.