Reliability algorithms
Service startup order
Plan startup for services whose dependencies must be ready first. Detect cycles rather than waiting forever.
In production
Service boot order with a cycle hangs forever. A wrong topological order starts a dependent before its dependency.
What it must return
Emit a valid startup order choosing the lexicographically smallest ready service at each step, or None when a cycle remains.
- Input maps every service name to a list of dependency names; every dependency is also a key. Lists have no duplicates. Choose the lexicographically smallest currently ready service at each step. Return None if there is a cycle.
- Do not mutate input values. Use the Python standard library only.
Edge cases
- Every dependency name is also a key.
- Tie-break is lexicographically smallest ready name.
- If you emit fewer than all services, return None.
Signature
startup_order(dependencies)Hints
Second hint
A partial sketch
The reference solution opens after the last hint.
Loading editor…
Dependency chain
dependencies
{
"api": [
"db"
],
"worker": [
"db"
],
"db": []
}Expected
[ "db", "api", "worker" ]
Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 10 in Reliability algorithms passed in Python on this device.