BuildSeniorBackendAuto-graded
Order a graph so dependencies come before dependents
Write a topological sort that puts every dependency first and raises an error when the graph has a cycle.resolve_order(graph) takes a map from each node to its direct dependencies and should return an order where every dependency comes before the node that needs it. Each node appears exactly once, including nodes that only show up as a dependency (even when they are never a key) and nodes with no links at all. If the graph has a cycle of any length, it must raise CycleError. Any valid order is accepted.45 min
Python
Goals
- Every node of the graph appears exactly once: each key, each dependency (even one that is never a key itself) and each node with no links at all.
- Every dependency comes before the node that needs it, through long chains, shared dependencies and wide fan-outs.
- A graph with a cycle of any length, a self-loop included, raises
CycleErrorand never loops forever.
What it measures
Topological orderingPutting every dependency before its dependent, through long chains, shared dependencies and wide fan-outs.
Cycle detectionRaising CycleError on cyclic graphs, self-loops included, without ever hanging.
Complete outputReturning every node exactly once, dependency-only and disconnected ones included.
Your environment
Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish
Start this lab
45 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo