PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Notion

Design a text editor with undo/redo

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of stateful data structures, operation/command semantics for reversible actions, undo/redo stack management, interface design, complexity analysis, and test coverage for mutable editors.

  • Medium
  • Notion
  • Coding & Algorithms
  • Software Engineer

Design a text editor with undo/redo

Company: Notion

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Implement a text document editor that supports the following operations: insert(chars) appends characters to the end; delete(k) removes up to k characters from the end (if k exceeds the current length, delete whatever exists); undo_last() undoes the most recent effective operation; redo_last() re-applies the last undone operation. Define an Operation interface with apply(doc) -> doc and rollback_operation() -> Operation to produce the inverse operation for undo/redo. Maintain undo and redo stacks; applying any new operation clears the redo stack. Provide get_current_content() -> str. Handle edge cases such as consecutive deletes, deleting from an empty document, attempting undo/redo when their stacks are empty, and ensuring only effective deletes are recorded for undo. Analyze time and space complexity for each operation and justify your data structure choices. Write unit tests covering: simple undo/redo flows, multiple consecutive deletions, very large deletions that exceed current length, sequences with no insertions, and idempotent redo when no redo is possible.

Quick Answer: This question evaluates understanding of stateful data structures, operation/command semantics for reversible actions, undo/redo stack management, interface design, complexity analysis, and test coverage for mutable editors.

Related Interview Questions

  • Implement a DAG task graph - Notion (medium)
  • Implement Table Aggregation - Notion (easy)
  • Implement text editor with undo/redo - Notion (Medium)
Notion logo
Notion
Aug 13, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
38
0

Implement a text document editor that supports the following operations: insert(chars) appends characters to the end; delete(k) removes up to k characters from the end (if k exceeds the current length, delete whatever exists); undo_last() undoes the most recent effective operation; redo_last() re-applies the last undone operation. Define an Operation interface with apply(doc) -> doc and rollback_operation() -> Operation to produce the inverse operation for undo/redo. Maintain undo and redo stacks; applying any new operation clears the redo stack. Provide get_current_content() -> str. Handle edge cases such as consecutive deletes, deleting from an empty document, attempting undo/redo when their stacks are empty, and ensuring only effective deletes are recorded for undo. Analyze time and space complexity for each operation and justify your data structure choices. Write unit tests covering: simple undo/redo flows, multiple consecutive deletions, very large deletions that exceed current length, sequences with no insertions, and idempotent redo when no redo is possible.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Notion•More Software Engineer•Notion Software Engineer•Notion Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.