Spot the bug in the graph search

from Recursion
Python 3.14 intermediate 4 min 1 issue to find

Find the state-lifetime bug in this graph search.

Python
def contains(node, target, seen=set()):
    if node["id"] in seen:
        return False
    seen.add(node["id"])
    if node["id"] == target:
        return True
    return any(contains(child, target, seen) for child in node["children"])
Open in playground
Report an error