Deep Copy a Fulfillment Network Graph With Cycles

Last updated: November 29, 2026

Quick Overview

Given a reference to one node of a connected, undirected fulfillment network where each node has an ID and a list of neighbor nodes, return a deep copy of the whole graph.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a reference to one node of a connected, undirected fulfillment network where each node has an ID and a list of neighbor nodes, return a deep copy of the whole graph.

An Amazon technical screen graph question about snapshotting a network topology for simulation. The interviewer checks that you map each original node to its clone before visiting neighbors, so cycles and shared neighbors do not produce duplicate clones or infinite loops.

What the Interviewer Expects
  • Use a hash map from original node to clone
  • Create the clone before exploring neighbors
  • Traverse with BFS or DFS and wire neighbor lists
  • Handle the empty graph and a single self-contained node
  • Verify the copy shares no objects with the original
Key Topics to Cover
Graph Cloning
BFS
Hash Map
Cycle Handling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you copy a graph that is not connected, given a list of all nodes?
  • How would you serialize this graph to send to another service?
  • What changes for a directed graph with edge weights?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: a Node with val and neighbors, or None. Output: the clone of that node, where the cloned graph has the same structure and values but all new objects....

High-Level Design

BFS from the given node. The map clones from original to copy doubles as the visited set. When we first see a node we create its clone and enqueue the original. When we dequeue a node, for each neig...


Submit Your Answer
Markdown supported