AlgoForge
LearnPracticeMockPricing
AlgoForge

Master DSA patterns and ace your next technical interview.

Learn

  • Curriculum
  • Problems
  • Daily Challenge
  • Mock Interview

Account

  • Dashboard
  • Pricing
  • Sign In
  • Get Started

Company

  • Privacy Policy
  • Terms of Service

© 2026 AlgoForge. All rights reserved.

Built for engineers who ship.

mediumGraphs

Clone Graph

## Problem

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

Each node in the graph contains a value (`int`) and a list (`List[Node]`) of its neighbors.

> **Input format:** Adjacency list as a list of lists. `adjList[i]` contains the neighbors of node `i+1` (1-indexed values). Return the adjacency list of the cloned graph.

Examples

Input
adjList = [[2,4],[1,3],[2,4],[1,3]]
Output
[[2,4],[1,3],[2,4],[1,3]]
4-node cycle: 1-2-3-4-1.
Input
adjList = [[]]
Output
[[]]
Single node, no neighbors.
Input
adjList = []
Output
[]
Empty graph.

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 in the graph. The Graph is connected and all nodes can be visited starting from the given node.
Python
Loading...