Zero To DSAZero To DSA
Privacy Policy
Number of IslandsCourse Schedule

Clone Graph

medium
Time: O(V + E)
Space: O(V)

Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph.

Constraints

  • The number of nodes is in the range [0, 100].

Examples

Input: adjList = [[2,4],[1,3],[2,4],[1,3]]
Output: [[2,4],[1,3],[2,4],[1,3]]
The graph has 4 nodes.