Is the Build Order Feasible?
mediumA monorepo has n packages, numbered 0 to n - 1. Each rule [a, b] in deps means package a depends on package b — b must be built before a.
Return True if there exists some order that builds all n packages, or False if the dependency rules make it impossible (i.e. they contain a cycle).
Example 1
in n = 2, deps = [[1, 0]]
out True
Build 0, then 1.
Example 2
in n = 2, deps = [[1, 0], [0, 1]]
out False
Each package waits on the other — deadlock.
Constraints
- · 1 <= n <= 100
- · 0 <= len(deps) <= 500
- · deps[i] = [a, b] with 0 <= a, b < n
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.