Statement
hard
Pipeline stage order
Implement `stage_order(graph)` — the run order of CI/CD stages.
`graph` is a dict `{stage: [stages it depends on]}`.
Rules:
- a dependency must come before the stage that needs it;
- when several stages are ready, pick the lexicographically smallest one;
- every dependency must be a key of the graph, otherwise `ValueError`;
- a dependency cycle is a `ValueError`;
- empty graph — empty list;
- a repeated dependency must not break the order.
AI mentor
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and ask
Hints
1 of 3 unlocked · attempts: 0
Hint 1
How do you find a stage that can run first if all you know are its dependencies?
Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts