A monorepo has n packages numbered 0 to n - 1. Each deps[i] = [a, b] means package a depends on package b, so b must be built before a.
Write canFinish(n, deps) that returns true if there is some order that builds every package after everything it depends on, and false if the dependencies go in a circle.
Input: n = 3, deps = [[1,0],[2,1]] Output: true
Build 0, then 1, then 2.
Input: n = 2, deps = [[0,1],[1,0]] Output: false
Each package waits for the other, so neither can start.
1 <= n <= 100000 <= deps.length <= 500000 <= a, b < nRun tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #439 Can the Build Finish?. 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.