Notice Period

Mirror the Network

medium

Before a risky migration, an ops team wants a deep copy of their service mesh so they can rehearse on the replica.

The mesh is an undirected connected graph given as a 1-indexed adjacency list: mesh[i] lists the (1-indexed) neighbors of node i + 1. Build a completely independent copy — new node objects, same wiring — and return its adjacency list in the same 1-indexed format. An empty input means an empty mesh; return [].

(In an interview you'd receive a node object and return the cloned node; here the adjacency list stands in for both, so your copy must reconstruct the structure node by node, not just echo the input.)

Example 1
in mesh = [[2,4],[1,3],[2,4],[1,3]]
out [[2,4],[1,3],[2,4],[1,3]]
A 4-node ring: 1–2–3–4–1. The clone has identical wiring.
Example 2
in mesh = [[]]
out [[]]
One node, no edges.
Example 3
in mesh = []
out []
Constraints
  • · 0 <= number of nodes <= 50
  • · the graph is connected and undirected
  • · no self-loops or duplicate edges
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.