← Questions

Clone graph

0
AbridgeCodingLast asked Sep 2026

Given a node of a connected undirected graph, where each node holds a value and a list of neighbors, return a deep copy of the whole graph: new nodes, the same values and the same edges, with each neighbor list in the same order. The problem may be dressed up in a domain story, so recognize it underneath. Do it with BFS or DFS and a map from original to copy.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding