Clone a graph (coding problem).
Asked in the technical panel, manager plus 2 senior developers. This was a live-coding exercise.
Implement clone_graph(graph). The input is a dictionary mapping each string node label to a list of adjacent string labels. The graph may contain cycles, self-loops, isolated nodes, and disconnected components. Every referenced neighbor appears as a key in graph.
Return a new adjacency-list dictionary representing a deep copy of the graph. Preserve every node and edge, but create new adjacency lists rather than returning the input object.
def clone_graph(graph):