All questions
Hard2026-08-10

Design Microsoft Word — LLD with Undo/Redo

Company
Adobe
Role

MTS-2 (C++)

Round

Round 3 (LLD)

LLDDesign PatternsOOPCommand Pattern

Problem Statement

Design a simplified version of Microsoft Word that supports:

  1. Multiple font types (Arial, Times New Roman, etc.)
  2. Font styles (Bold, Italic, Underline) — can be combined
  3. Font sizes
  4. Text formatting and paragraphs
  5. Inline images
  6. Undo / Redo functionality

The design should be extensible — adding new formatting options or features should not require modifying existing code.

Requirements

  • Support rich text with mixed formatting within a single paragraph
  • Images can be placed inline with text
  • Undo/Redo should work for any operation (typing, formatting changes, image insertion)
  • Design for extensibility (Open/Closed principle)

What the Interviewer Expects

  1. Document structure — Composite Pattern:

    • Document contains Page[]
    • Page contains Block[] (paragraphs, images)
    • Paragraph contains TextRun[] (each run has uniform formatting)
    • TextRun has content + FormattingStyle
  2. Formatting — Strategy/Decorator Pattern:

    • FormattingStyle object with font, size, bold, italic, underline
    • Styles can be composed/stacked
    • New styles added without changing existing code
  3. Undo/Redo — Command Pattern:

    • Every action is a Command object: execute() and undo()
    • CommandHistory maintains two stacks (undo stack, redo stack)
    • Executing new action clears redo stack
    • Types: InsertTextCommand, DeleteTextCommand, FormatCommand, InsertImageCommand
  4. Extensibility:

    • Adding "Strikethrough" = new style flag, no existing code changes
    • Adding "Table" = new Block subclass, composites handle it naturally

Follow-ups

  1. How would you handle collaborative editing (multiple cursors)?
  2. How would you persist the document? What serialization format?
  3. How would you implement "group undo" (undo a bulk formatting change as one step)?
  4. What's the memory cost of storing every command? How would you optimize for large documents?
  5. How would you add a plugin system for third-party formatting extensions?
🧠

No solution provided

Think through it. That's how you build real interview muscle.

Share: