Dependency Resolution
GRAPH
DEPTH-FIRST SEARCH
Problem
Imagine a project with several tasks, each labeled from 0 to numTasks
- 1. You have an array of dependencies where dependencies[i] = [a, b]
indicates that task b
must be completed before task a
.
Determine if it is possible to complete all tasks given these constraints.
Examples
canComplete(4, [[2, 0], [1, 0], [3, 1], [3, 2]]) // return true /* Why? Task 0 must be completed before 1 and 2 Task 1 must be completed before 3 Task 2 must be completed before 3 Valid sequence is 0 -> 1 -> 2 -> 3 or 0 -> 2 -> 1 -> 3 */
Loading...
Loading...Loading...