Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Deep Clone and Pitfalls
00:00
5 left

Deep Clone and Pitfalls

HardPython

Problem

The Twitch Creator Dashboard may need an independent copy of nested editor state before applying speculative updates. Implement deep_clone(obj) to clone a supported object graph without sharing mutable containers with the original.

The input may contain nested dictionaries and lists. Dictionary keys are strings, and leaf values are JSON-compatible primitives: strings, numbers, booleans, or None. The input can also contain repeated references or cycles, even though JSON examples cannot represent object identity directly.

Requirements

  1. Return a structurally equivalent clone.
  2. Mutating any cloned dictionary or list must not mutate the original object.
  3. Preserve graph topology: if two original fields reference the same mutable object, the corresponding cloned fields must reference the same cloned object.
  4. Handle cycles without infinite recursion.
  5. Raise TypeError for unsupported value types.

Constraints

  • The object graph contains at most 10^4 dictionaries and lists
  • Dictionary keys are strings
  • Supported leaves are strings, integers, floats, booleans, and None
  • The maximum nesting depth is at most 500
  • Cycles and repeated references may occur

Function Signature

def deep_clone(obj):
Interviewer

Your question is Deep Clone and Pitfalls. Start with the requirements in the Question tab.

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.