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
Move and Copy Constructors
00:00
5 left

Move and Copy Constructors

MediumPython

Problem

In Luxoft Singapore automotive cockpit integration code, components may duplicate a mutable resource or transfer its ownership. Implement both behaviors through a command processor.

A copy operation must create an independent deep copy of a source buffer. Later mutations to either buffer must not affect the other. A move operation must transfer the source buffer's underlying list to the destination in O(1) time, then leave the source in a valid empty state. The destination name is guaranteed not to exist before the operation.

Formal Specification

Implement manage_buffers(initial, operations).

  • initial is a dictionary mapping unique string names to lists of integers.
  • operations is a list of commands:
    • ['copy', source, destination]
    • ['move', source, destination]
    • ['append', name, value]
    • ['clear', name]
  • Every referenced buffer exists when used.
  • Return a dictionary containing every buffer name created or present during execution, including moved-from sources. Values must be the final integer lists.
  • Do not use serialization or a whole-state deep copy for every command.

Constraints

  • 1 <= len(initial) <= 10^4
  • 0 <= len(operations) <= 10^5
  • 0 <= len(initial[name]) <= 10^4
  • -10^9 <= value <= 10^9
  • Destination names are unique and do not already exist
  • All operations are valid

Function Signature

def manage_buffers(initial, operations):
Interviewer

Your question is Move and Copy Constructors. 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.