Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deep Clone Nested Structures

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Deep Clone Nested Structures. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement a function deep_clone(value) that returns a deep copy of a JavaScript-style value represented in Python using dictionaries, lists, primitives, and None. The clone must recursively copy nested lists and dictionaries so that modifying the result does not affect the original. Handle cyclic references by preserving structure in the clone rather than recursing forever.

Constraints

  • Input may be a primitive, None, list, or dictionary
  • Nested structure size is at most 10^4 total elements
  • Dictionary keys are strings
  • Cycles and repeated references may appear in the input

Function Signature

def deep_clone(value):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output