PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Notion

Implement text editor with undo/redo

Last updated: Mar 29, 2026

Quick Overview

This question evaluates implementation-level skills in state management, reversible operation design, and efficient mutable-string handling within the Coding & Algorithms domain.

  • Medium
  • Notion
  • Coding & Algorithms
  • Software Engineer

Implement text editor with undo/redo

Company: Notion

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Implement a text document with undo/redo based on this Python skeleton: class Operation: class InsertAtEndOperation(Operation): def __init__(self, chars_to_insert: str): self.chars_to_insert = chars_to_insert class DeleteFromEndOperation(Operation): def __init__(self, num_chars_to_delete: int): self.num_chars_to_delete = num_chars_to_delete class TextDocument: def __init__(self) -> None: def apply_operation(self, op: Operation) -> None: def get_current_content(self) -> str: return self.doc def undo_last(self) -> None: def redo_last(self) -> None: Requirements: - apply_operation must support appending chars_to_insert to the end and deleting up to num_chars_to_delete characters from the end (no error if fewer characters exist). - get_current_content returns the current string; the document starts empty. - undo_last reverts the most recent applied operation; redo_last reapplies the most recent undone operation. - After any successful apply_operation, clear the redo history. - Ensure each operation runs in time proportional to the size of the change (avoid copying the entire document per step). Choose suitable data structures and an approach to store inverse operations. Discuss: data structures used (e.g., stacks/chunked buffer), how inverse operations are computed, time/space complexity of each method, and key edge cases (e.g., deleting more than available, multiple undos/redos).

Quick Answer: This question evaluates implementation-level skills in state management, reversible operation design, and efficient mutable-string handling within the Coding & Algorithms domain.

Related Interview Questions

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

Implement a text document with undo/redo based on this Python skeleton:

class Operation:

class InsertAtEndOperation(Operation): def init(self, chars_to_insert: str): self.chars_to_insert = chars_to_insert

class DeleteFromEndOperation(Operation): def init(self, num_chars_to_delete: int): self.num_chars_to_delete = num_chars_to_delete

class TextDocument: def init(self) -> None:

def apply_operation(self, op: Operation) -> None:

def get_current_content(self) -> str:
    return self.doc

def undo_last(self) -> None:

def redo_last(self) -> None:

Requirements:

  • apply_operation must support appending chars_to_insert to the end and deleting up to num_chars_to_delete characters from the end (no error if fewer characters exist).
  • get_current_content returns the current string; the document starts empty.
  • undo_last reverts the most recent applied operation; redo_last reapplies the most recent undone operation.
  • After any successful apply_operation, clear the redo history.
  • Ensure each operation runs in time proportional to the size of the change (avoid copying the entire document per step). Choose suitable data structures and an approach to store inverse operations. Discuss: data structures used (e.g., stacks/chunked buffer), how inverse operations are computed, time/space complexity of each method, and key edge cases (e.g., deleting more than available, multiple undos/redos).

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.