Dashboard
LC #133

Clone Graph

Pattern · ?AmazonGoogleMetaLinkedIn

Problem

Return a deep copy of a connected undirected graph.

Constraints

  • 0 ≤ n ≤ 100 nodes
  • 1 ≤ Node.val ≤ 100 (unique)
  • No repeated edges, no self-loops
  • Connected graph

Example

Input
adjList = [[2,4],[1,3],[2,4],[1,3]]
Output
Deep copy of the graph
Why
Node 1 connects to 2 and 4. Node 2 connects to 1 and 3. All connections are bidirectional

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗