Graph Theory37 sections · 1633 units
Open in Course

LeetCode 133 Clone Graph - Problem Statement

(LeetCode 133)

You're given a node in a connected undirected graph. Each node contains a value and a list of neighbors. Your task: return a deep copy of the graph.

This means creating completely new node objects with the same values and connections as the original. If node 11 connects to node 22 in the original, your copied node 11 must connect to your copied node 22.

The challenge: as you traverse the graph with DFS, how do you avoid creating duplicate copies of the same node? If node 11 and node 22 both reference node 33, you need exactly one copy of node 33.