Problem
Given a set of build layers (or packages) and their dependencies, return a valid build order in which every layer appears after all the layers it depends on. If the dependencies contain a cycle, no valid order exists — detect and report it.
Input / Output
- Input: a list of nodes and directed dependency edges (A->B means B must be built before A).
- Output: a topologically ordered list of nodes, or an error identifying a cycle.
Constraints
- Up to 10^4 nodes and their edges.
- A node with no dependencies can be built at any time; ordering among independent nodes is unconstrained.
Example
- deps A->B, B->C => build order C, B, A.
- deps A->B, B->A => error: cycle between A and B.