Your question is Batch Commit and Batch Undo. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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.
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.
def process_operations(initial_document, actions):