Your question is Detect and Resolve Retain Cycles. 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.
Write a function to detect and resolve retain cycles in a provided block of asynchronous code.
Model retained references as a directed graph, where each edge means the source strongly retains the target. Return the directed edges that should be made weak to remove all cycles, using depth-first traversal order and preserving the supplied node and edge order. The function receives nodes and edges, and returns a list of [source, target] edges identified as DFS back-edges. Each node name is unique, and every edge references a listed node.
def resolve_retain_cycles(nodes, edges):