Clone Service Topology
A staging environment needs a deep copy of the production service dependency graph so chaos tests cannot touch the live nodes. Given a reference to one node in a connected undirected graph, return a deep clone of the whole graph.
Problem
Given a node in a connected undirected graph where each node has an integer value and a list of neighbours, return a deep copy: new node objects with the same values and the same neighbour structure.
Input
A start node; the graph has up to n nodes (0 ≤ n ≤ 100) with unique values 1..n, given as an adjacency list for description.
Output
The cloned graph's start node (described via its adjacency list).
Constraints
- 0 ≤ n ≤ 100; node values are unique
- The graph is connected and undirected
- No self-loops or repeated edges
Examples
Example 1
Input
adjacency = {1: [2, 4], 2: [1, 3], 3: [2, 4], 4: [1, 3]}, start = 1Output
{1: [2, 4], 2: [1, 3], 3: [2, 4], 4: [1, 3]}A 4-cycle is cloned into brand-new nodes with identical connections.
Example 2
Input
adjacency = {1: []}, start = 1Output
{1: []}A single isolated node clones to one new node with no neighbours.