Model Versioning
Model Versioning
You are building a model registry. Given a list of model versions, each with a name, accuracy, latency, and timestamp, decide which model should be promoted to production.
Promotion Rules
A model is promoted if it has the highest accuracy. If two models share the same accuracy, prefer the one with lower latency. If still tied, prefer the most recent model (latest timestamp).
Return the name of the model to promote.
Examples
Input:
models = [ {"name": "v1", "accuracy": 0.85, "latency": 120, "timestamp": "2024-01-15"}, {"name": "v2", "accuracy": 0.91, "latency": 95, "timestamp": "2024-02-20"}, ]
Output:
"v2"
v2 has higher accuracy (0.91 vs 0.85), so it is promoted.
Input:
models = [ {"name": "v1", "accuracy": 0.90, "latency": 100, "timestamp": "2024-01-10"}, {"name": "v2", "accuracy": 0.90, "latency": 80, "timestamp": "2024-03-05"}, ]
Output:
"v2"
Both have accuracy 0.90. v2 wins on lower latency (80 vs 100).
Hint 1
Python's sorted() accepts a key function. You can sort by a tuple of criteria.
Hint 2
Negating a value reverses its sort order without changing the direction of other keys.
Requirements
- Compare models by accuracy (higher is better)
- Break accuracy ties using latency (lower is better)
- Break remaining ties using timestamp (latest wins)
- Return the name (string) of the promoted model
Constraints
- 1 ≤ len(models) ≤ 1000
- 0.0 ≤ accuracy ≤ 1.0
- latency is a positive integer (milliseconds)
- timestamp is an ISO date string (YYYY-MM-DD)
- All model names are unique
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: array
Model Versioning
Model Versioning
You are building a model registry. Given a list of model versions, each with a name, accuracy, latency, and timestamp, decide which model should be promoted to production.
Promotion Rules
A model is promoted if it has the highest accuracy. If two models share the same accuracy, prefer the one with lower latency. If still tied, prefer the most recent model (latest timestamp).
Return the name of the model to promote.
Examples
Input:
models = [ {"name": "v1", "accuracy": 0.85, "latency": 120, "timestamp": "2024-01-15"}, {"name": "v2", "accuracy": 0.91, "latency": 95, "timestamp": "2024-02-20"}, ]
Output:
"v2"
v2 has higher accuracy (0.91 vs 0.85), so it is promoted.
Input:
models = [ {"name": "v1", "accuracy": 0.90, "latency": 100, "timestamp": "2024-01-10"}, {"name": "v2", "accuracy": 0.90, "latency": 80, "timestamp": "2024-03-05"}, ]
Output:
"v2"
Both have accuracy 0.90. v2 wins on lower latency (80 vs 100).
Hint 1
Python's sorted() accepts a key function. You can sort by a tuple of criteria.
Hint 2
Negating a value reverses its sort order without changing the direction of other keys.
Requirements
- Compare models by accuracy (higher is better)
- Break accuracy ties using latency (lower is better)
- Break remaining ties using timestamp (latest wins)
- Return the name (string) of the promoted model
Constraints
- 1 ≤ len(models) ≤ 1000
- 0.0 ≤ accuracy ≤ 1.0
- latency is a positive integer (milliseconds)
- timestamp is an ISO date string (YYYY-MM-DD)
- All model names are unique
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: array