Here's how it works in three steps per node:
Base case: if the current node is null, return null. If you've already copied this node (it's in your map), return the existing copy.
Create a new node with the same value as the original.
Add it to your map immediately, before processing neighbors. This prevents infinite loops when the graph has cycles.
For each neighbor of the original node, recursively clone that neighbor and add the result to your new node's neighbor list. The Core idea: you must add the node to the map before processing neighbors. Otherwise, circular references cause infinite recursion.