Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph. Each node in the graph contains a value (int) and a list of its neighbors.
{}"Because edges are bidirectional, cloning node A's neighbor B will immediately attempt to clone B's neighbor A, creating an infinite ping-pong loop without a visited map."
"Instantiate Node copy = new Node(node.val) and store it in map.put(node, copy) BEFORE making any recursive neighbor calls. This breaks cycles instantly."
"The helper clone(node, map) returns the cloned reference. If map.containsKey(node), return map.get(node). Otherwise clone, memoize, iterate neighbors, and return."
"Every node and edge is visited and duplicated exactly once. Time complexity is $O(V + E)$ and auxiliary space is $O(V)$ for the HashMap and recursion stack depth."