Clone Graph
Clone an undirected graph given its adjacency list representation.
Examples
Input: [[2,4],[1,3],[2,4],[1,3]]
Output: [[2,4],[1,3],[2,4],[1,3]]
Input: [[]]
Output: [[]]
Hints
Start by creating a copy of the starting node and add it to the map. Then, use a queue to perform a BFS traversal, cloning each node's neighbors and adding them to the queue if they haven't been cloned yet.
For each node in the queue, iterate through its neighbors in the original graph. If a neighbor hasn't been cloned, create a clone, add it to the map, and enqueue it. Then, add the cloned neighbor to the current node's cloned neighbors list.
After the BFS completes, construct the adjacency list for the cloned graph by iterating through the map and collecting the neighbors for each cloned node, ensuring the order matches the original graph.
Related Problems
Clone Graph
Clone an undirected graph given its adjacency list representation.