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
Batch Commit and Batch Undo
00:00
5 left

Batch Commit and Batch Undo

MediumPython

Problem

Figma groups several related FigJam or Figma Design canvas edits into one history entry so a single undo removes the entire user action. Implement batch_commit and batch_undo for a simplified document model.

A document is a dictionary mapping object IDs to integer values. Each change is represented as [object_id, before, after]. A batch commit must apply every change and store the entire batch as one undo entry. A batch undo must restore the most recent batch in reverse order. If there is no committed batch, undo does nothing.

Implement process_operations, which uses these operations:

  • {"type": "commit", "changes": [[id, before, after], ...]}
  • {"type": "undo"}

Return the final document dictionary. The input document should not be mutated by the caller.

Formal Specification

Input: initial_document, a dictionary from strings to integers, and actions, a list of commit or undo dictionaries.

Output: A dictionary containing the document state after all actions.

Constraints

  • 0 <= len(actions) <= 10^5
  • Each action contains at most 10^4 changes
  • Each object appears at most once within a committed batch
  • Every before value matches the current document value
  • Object IDs are nonempty strings and values are integers

Function Signature

def process_operations(initial_document, actions):
Interviewer

Your question is Batch Commit and Batch Undo. 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.