Your question is Detect Circular Dependency. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
EPAM DIAL may represent workflow steps as a directed dependency graph, where an edge A -> B means step A must complete before step B. Implement a function that determines whether the graph contains a circular dependency.
A circular dependency exists when following directed edges can return to a node already on the current traversal path. A self-dependency such as A -> A is also a cycle.
Given graph, a dictionary mapping each node to a list of nodes that depend on it, return True if the directed graph contains a cycle. Return False otherwise. Nodes that appear only in dependency lists must also be considered part of the graph.
def has_circular_dependency(graph):