HardPro challengePythonJavaScriptTypeScript

Dependency Graph Resolve

Node.jsGraphsAlgorithms

Topological sort. Input: { a: ['b', 'c'], b: ['c'], c: [] } means
"a depends on b and c, b on c".

Return tasks in execution order (dependencies first). Tie-break alphabetically.
On cycle, return null.

Sample tests

Test #1Simple chain
Input: [{"a":["b"],"b":[]}]
Output: ["b","a"]
Test #2Independent nodes
Input: [{"a":[],"b":[]}]
Output: ["a","b"]
Test #3Cycle
Input: [{"a":["b"],"b":["a"]}]
Output: null
Test #4Diamond
Input: [{"a":["b","c"],"b":["c"],"c":[]}]
Output: ["c","b","a"]
Test #5Alphabetical roots
Input: [{"a":[],"z":["a"]}]
Output: ["a","z"]