Algorithm · Amazon · Medium
You are given n tasks numbered from 0 to n - 1 and a list of dependency pairs dependencies. Each pair [a, b] means task b is a prerequisite of task a, so b must be completed before a can begin. Return an array containing one valid execution order of all tasks. The array must include every task exactly once, and every prerequisite must be satisfied. If the dependency graph contains a cycle, return an empty array. If multiple valid orderings exist, any one of them is accepted.…
Checking your access…