MongoDBSeptember 2026
Interview question
Given a directed package dependency graph and a target package, return a valid build order containing the target and its transitive dependencies, building every dependency before the package that requires it. Detect cycles reachable from the target and report that no build is possible. Do not include unrelated packages. Example: A depends on B,C; B on E; C on D,E,F; D,E,F have no dependencies; G depends on R. For target A, one valid order is E,B,D,F,C,A.
Follow-up questions
- How will you distinguish an active DFS node from a fully processed node to detect cycles without rebuilding shared dependencies?
- How should you handle a referenced package with no entry in the dependency map?
- What happens if a cycle exists in an unrelated component, such as X depending on Y, Y on Z, and Z on X? Explain why processing the entire graph could reject a valid target build.