Clone a Directed Graph

Clone a given directed graph by making a deep copy of it.

Statement

Given the root node of a directed graph, clone this graph by creating its deep copy, such that the cloned graph has the same vertices and edges as the original graph.

Example

Let’s look at the graphs below as an example. If the input graph is G=(V,E)G = (V, E) where VV is a set of vertices and EE is a set of edges, then the output graph (the cloned graph) is G=(V,E)G' = (V', E') such that V=VV = V' and E=EE = E'.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.