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
m = [{"name":"big","quality":0.95,"price":10.0},{"name":"small","quality":0.8,"price":1.0}]
print(route_model(m, 0.75))small
-
Filter for qualified models: We check each model against the minimum quality bar of .
- "big" has a quality of , which is , so it qualifies.
- "small" has a quality of , which is , 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 .
- "small" has a price of .
- Comparing the prices, , 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
- The final output is
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).
modelsis non-empty.