Given a starting node in a directed graph of immutable nodes, find a set of nodes that either:
- have an IP address, or
- can reach a node having an IP address.
Node in the graph is represented as:
Node {label -> String // unique in the graph
connections -> List[Node]
hasIpAddress -> Boolean
}
(t) -> Node has IP address
(f) -> Node doesn’t have an IP address
This problem asks you to collect all nodes in a directed graph that either already have an IP address or can reach one through outgoing edges. A typical solution uses DFS with memoization/visited tracking to avoid revisiting nodes and to handle cycles safely. The main challenge is propagating the result backward so that any node with a path to an IP-address node is included in the final set.