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 Without Libraries
00:00
5 left

Deep Clone Without Libraries

HardPython

Problem

Netcracker Digital Platform configuration data can contain deeply nested dictionaries and lists. Implement a function that creates a fully independent clone without using external libraries.

The input is a Python value composed of dict, list, str, int, float, bool, and None. Dictionary keys are strings. Mutable objects may be shared by multiple fields or may reference themselves indirectly.

Your clone must satisfy these requirements:

  1. Copy every dictionary and list so that modifying the clone cannot modify the original.
  2. Return immutable values directly because they do not require cloning.
  3. Preserve internal aliases. If two fields in the input reference the same mutable object, the corresponding fields in the clone must reference the same cloned object.
  4. Preserve cycles, such as a list that contains itself.
  5. Do not use copy.deepcopy or any external library.

The function should return the cloned value.

Constraints

  • The input contains only dict, list, str, int, float, bool, and None values.
  • Dictionary keys are strings.
  • The total number of dictionaries and lists is at most 10^5.
  • The input may contain shared references or cycles.
  • The nesting depth may be large.

Function Signature

def deep_clone(value):
Interviewer

Your question is Deep Clone Without Libraries. 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.