Your question is Detect Cycles in Trading Dependencies. 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.
AKUNA CAPITAL models relationships between trading components as a directed dependency graph. An edge A -> B means component A must be processed before component B.
Implement has_cycle(graph) to determine whether the directed graph contains a cycle. A cycle means that no valid processing order exists because at least one component depends, directly or indirectly, on itself.
graph: a dictionary mapping each component name to a list of components it directly depends on.True if the graph contains at least one directed cycle; otherwise return False.def has_cycle(graph):