This question evaluates proficiency with directed graph concepts and dependency resolution, focusing on cycle detection and selecting a single dependency edge whose removal renders the graph acyclic.
You are given dependencies between software pods. Each dependency is a directed edge u -> v meaning pod u must be built/installed before pod v.
Given:
n
: number of pods (labeled
0..n-1
)
edges
: list of directed dependency pairs
(u, v)
Return true if the dependency graph contains any cycle (i.e., it is impossible to build all pods), otherwise return false.
Using the same input format (directed edges), if the graph has a cycle, return any single directed edge (u, v) such that removing that edge makes the graph acyclic.
If the graph is already acyclic, return an empty result (e.g., null / (-1, -1) depending on your language).
Input: n = 3, edges = [(0,1),(1,2),(2,1)]
true
(2,1)
(removing it breaks the cycle)