Clone Graph Problem
Clone Graph Problem — ExecCode Medium DSA Practice
Solve the Clone Graph problem on ExecCode. Free online medium DSA practice in Data Structures and Algorithms. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph. Each node contains a value and a list of neighbors.
Examples
Input adjList = [[2, 3, 4], [1, 3, 6], [1, 2, 4, 5, 6], [1, 3, 5], [3, 4], [2, 3]]; Output [[2, 3, 4], [1, 3, 6], [1, 2, 4, 5, 6], [1, 3, 5], [3, 4], [2, 3]]. Input adjList = [[]]; Output [[]]. Input adjList = [[2], [1]]; Output [[2], [1]]
Constraints
The number of nodes in the graph is in the range [0, 100]. 1 ≤ Node.val ≤ 100 Node.val is unique for each node. There are no repeated edges and no self-loops.
Practice Clone Graph free on ExecCode. Browse DSA problems, topic map, and placement guides.