Given a reference to a node in a connected undirected graph, create and return a deep copy of the graph.
Each node contains:
Graph properties:
Constraints:
Examples:
// Example 1:
// Graph: 1 -- 2 -- 3
// |
// 3
const adjList1 = [[2], [1, 3], [2]];
console.log(cloneGraph(createGraph(adjList1)));
// Output: [[2], [1,3], [2]]
// Explanation: 3 nodes where:
// Node 1 connects to 2
// Node 2 connects to 1 and 3
// Node 3 connects to 2
// Example 2:
const adjList2 = [[]];
console.log(cloneGraph(createGraph(adjList2)));
// Output: [[]]
// Explanation: Single node with no neighbors
// Example 3:
const adjList3 = [];
console.log(cloneGraph(createGraph(adjList3)));
// Output: []
// Explanation: Empty graph