Back to problems

Dependency Resolution / Build Order

Algorithm · Airbnb · Medium

Problem You are given a collection of tasks and a set of dependency rules. Your job is to produce a valid sequence in which to execute them. A dependency is expressed as a pair (A, B) and means: before you can perform task A, task B must already be completed (equivalently, a directed edge $$B \to A$$ exists). If the dependency graph contains a cycle, it is impossible to finish every task. In that case, return an empty list. Function Signature n: number of tasks, labeled 0…

Checking your access…