Clone Graph
Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph.

30:00

Clone Graph
medium
Topics
Companies

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

Example 1:
Input: [[2,4],[1,3],[2,4],[1,3]]
Output: [[2,4],[1,3],[2,4],[1,3]]
Constraints:
  • The number of nodes is in the range [0,100][0, 100].

  • 1Node.val1001 \leq \text{Node.val} \leq 100

  • Node.val is unique for each node.

  • There are no repeated edges and no self-loops in the graph.

  • The graph is connected and all nodes can be visited starting from the given node.

Input
arr =[[2,4],[1,3],[2,4],[1,3]]

Checking if node 1 is cloned

1

2

3

4

Variables
No variables to display
DepthFunction Call
Stack empty
0/29