FreeCareerPath
Build the PrimitiveMedium

Clone Graph

Write `clone_graph(node)` returning a deep copy of a connected undirected graph. Each node has `val` and `neighbors`. The graph has cycles, so a naive traversal never terminates. Keep a map from original node to its copy and check it *before* recursing — the entry must be created before you walk the neighbours, or a cycle will still loop forever.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Clone Graph" are saved to your account — logging in takes a few seconds.

Clone Graph — FreeCareerPath