medium

Clone Graph

Given a reference to one node of a connected undirected graph, where each node has a value and a list of neighbours, return a deep copy of the entire graph.

Constraints
  • 0 ≤ number of nodes ≤ 100
  • Node values are unique 1..n
  • No self-loops or repeated edges
Examples
in: adjList = [[2,4],[1,3],[2,4],[1,3]]
out: A structurally identical graph made of new nodes

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.