Workspace/Coding labs
Loading progress

Select a route under hard constraints

Intermediate65 min

Each route has a unique name, quality estimate in [0,1], nonnegative local-credit cost, and nonnegative latency estimate. Validate all routes and limits as finite numbers, rejecting booleans. Filter by quality floor, available budget, and latency ceiling. Maximize success_value * quality - cost; break ties by lower cost then lexicographic name. Return a name or None when infeasible. These are invented task-level estimates, not actual vendor prices or performance.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

InputSwift q=.82,c=2; Careful q=.94,c=6; floor=.9,budget=8

Outputcareful

Only Careful satisfies the quality floor.
EXAMPLE 2

InputThe same routes with floor=.9,budget=5

OutputNone

Do not silently weaken a hard constraint.
solution.pyPython 3.12