← All problems

Clone Graph

Medium graphsdfshash maps LeetCode ↗
Deep-copy a connected undirected graph given a reference node.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n+e), Space O(n)

Common pitfalls

  • Infinite recursion on cycles (no map check)
  • Shallow copy of neighbor lists

Your solution

Log in to save your code and track progress.