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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Deep Clone Complex Objects
00:00
5 left

Deep Clone Complex Objects

HardPython

Problem

Amazon Alexa components may store nested state using dictionaries, lists, and sets. Implement deep_clone to create a fully independent copy while preserving the original structure's shared references and supporting cycles.

Formal Specification

The function receives one Python value containing only:

  1. Immutable primitives: None, booleans, integers, floats, strings, and bytes.
  2. Mutable containers: dictionaries, lists, and sets.
  3. Nested combinations of these values.

Return a deep clone with these guarantees:

  • No mutable container in the clone is the same object as its counterpart in the input.
  • Repeated references remain repeated references in the clone. If two fields reference the same original list, they must reference the same cloned list.
  • Cyclic references must terminate and remain cyclic in the clone.
  • Dictionary keys and values must be cloned when they contain supported compound values.
  • The input must not be modified.

You may use id(value) to identify object identity. Inputs contain at most 10,000 container objects and a nesting depth of at most 1,000.

Constraints

  • Supported values are None, booleans, integers, floats, strings, bytes, dictionaries, lists, and sets.
  • There are at most 10,000 container objects.
  • Nesting depth is at most 1,000.
  • Dictionary keys and set members are hashable.
  • The input may contain aliases and cyclic references.

Function Signature

def deep_clone(value):
Interviewer

Your question is Deep Clone Complex Objects. 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.