PIXELBANKv9.1.0
Menu

Route to the Cheapest Model Meeting Quality

Problem Statement

A router picks the cheapest model whose benchmark quality clears a required bar for a task. If none qualifies, fall back to the highest-quality model regardless of cost.

Background

Each model has a name, quality (0-1), and price (per call). Among models with quality >= min_quality, choose the lowest price (ties broken by higher quality, then name). If none meet the bar, return the model with the highest quality (ties: lower price, then name).

Your Task

def route_model(models, min_quality):

Return the chosen model's name.

Input Format

  • models: list of {"name": str, "quality": float, "price": float}, min_quality (float).

Output Format

  • A model name string.

Sample

m = [{"name":"big","quality":0.95,"price":10.0},{"name":"small","quality":0.8,"price":1.0}]
print(route_model(m, 0.75))

Output:

small

Example:

Input:
m = [{"name":"big","quality":0.95,"price":10.0},{"name":"small","quality":0.8,"price":1.0}]
print(route_model(m, 0.75))
Output:
small
Reasoning:
  • Filter for qualified models: We check each model against the minimum quality bar of 0.750.75.

    • "big" has a quality of 0.950.95, which is ≥0.75\ge 0.75, so it qualifies.
    • "small" has a quality of 0.80.8, which is ≥0.75\ge 0.75, so it also qualifies.
    • The list of qualified models is ["big", "small"].
  • Select the cheapest option: Since there are qualified models, we choose the one with the lowest price to minimize cost.

    • "big" has a price of 10.010.0.
    • "small" has a price of 1.01.0.
    • Comparing the prices, 1.0<10.01.0 < 10.0, so "small" is the cheaper option.
  • Verify tie-breakers: No tie-breaking is needed because the prices are distinct. If they were equal, we would look at quality (higher is better) and then name (alphabetical), but here the price difference is decisive.

  • Final Output: The name of the selected model is returned.

    • The final output is small

Constraints:

  • Prefer cheapest among quality >= min_quality (ties: higher quality, then name).
  • If none qualify, return the highest-quality model (ties: lower price, then name).
  • models is non-empty.
🔒

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.