Loading...
You are given n tasks labeled 0 to n - 1 and an array requirements where requirements[i] = [a, b] means task b must be completed before task a can start.
Return true if it is possible to complete all n tasks, and false otherwise. Completion is impossible exactly when some chain of requirements loops back on itself.
Input: n = 2, requirements = [[1,0]]
Output: true
Explanation: Complete task 0 first, then task 1. Every requirement is satisfied.
Input: n = 2, requirements = [[1,0],[0,1]]
Output: false
Explanation: Task 1 requires task 0 to be done first, and task 0 requires task 1 to be done first. The requirements are circular, so neither task can ever start.
n ≤2000requirements.length ≤5000requirements[i].length =2nrequirements[i] are unique.Click "Run" to test with sample cases or "Submit" to run all tests.