n modules numbered from 0 to n - 1. The list deps describes how they depend on each other: a pair [a, b] means module a uses module b, so b has to be built before a.
Modules are built one at a time. Decide whether there is an order in which all n modules can be built without breaking any dependency. Return True if such an order exists and False otherwise.n=4, deps=[[1, 0], [2, 1], [3, 1]] → True
The order 0, 1, 2, 3 works: module 1 waits only for 0, and modules 2 and 3 wait only for 1.
n=3, deps=[[0, 1], [1, 2], [2, 0]] → False
Module 0 waits for 1, module 1 waits for 2, and module 2 waits for 0: a closed loop, nothing can go first.
n=5, deps=[] → True
There are no dependencies, so the modules can be built in any order.
n ≤ 2000deps ≤ 5000deps is a pair [a, b] with 0 ≤ a, b < ndeps are distinctn=4, deps=[[1, 0], [2, 1], [3, 1]]
True
Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.