A CI system builds packages in rounds. In each round, it builds every package whose dependencies were all built in earlier rounds, all at the same time. Packages are numbered 0 to n - 1, and deps[i] = [a, b] means a depends on b.
Write buildRounds(n, deps) that returns how many rounds it takes to build every package, or -1 if the dependencies contain a circle.
Input: n = 4, deps = [[1,0],[2,0],[3,1],[3,2]] Output: 3
Round 1 builds 0. Round 2 builds 1 and 2 together. Round 3 builds 3.
Input: n = 3, deps = [] Output: 1
Nothing depends on anything, so everything builds in round 1.
1 <= n <= 100000 <= deps.length <= 500000 <= a, b < nRun tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #442 Fewest Build Rounds. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.