FastPrepText Document History
Problems/Text Document History

Text Document History

Notion logoNotion● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Several reports describe a text document with append at the end, delete from the end, undo, redo, and a current-content operation. Here the operations come as a stream in one batch, with a fixed outcome.

Our version is about 99% the same as the reported questions.

Process operations against an initially empty text document.

  • ["APPEND", text] appends text to the end.
  • ["DELETE", count] removes the final count characters.
  • ["UNDO"] restores the document state before the latest applied append or delete.
  • ["REDO"] reapplies the latest undone append or delete.
  • ["GET"] appends the current complete text to the result.

A new append or delete after an undo clears the redo history. An undo or redo with no available history has no effect. Return the values produced by GET operations in order.

Function

runTextDocument(operations: String[][]) → String[]

Examples

Example 1

operations = [["APPEND","hello"],["APPEND","!"],["DELETE","3"],["GET"],["UNDO"],["GET"],["REDO"],["GET"],["UNDO"],["APPEND","?"],["REDO"],["GET"]]return = ["hel","hello!","hel","hello!?"]

Undo and redo move between whole document states. Appending after the second undo clears the remaining redo state.

Constraints

  • 1 <= operations.length <= 20000.
  • Each operation has exactly one of the forms listed above.
  • Every appended text is a non-empty printable ASCII string.
  • Every delete count is a positive decimal integer no larger than the current document length.
  • The total length of all returned strings is at most 200000.

More Notion interview questions

  • Nested Todo ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Mutable Table AggregationsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
  • Block Type with the Most ChildrenPHONE SCREEN · Seen Mar 2026
  • Country with the Most EventsPHONE SCREEN · Seen Mar 2026
  • Event Type with the Most EventsPHONE SCREEN · Seen Mar 2026
  • Most Popular Active Plan for the Top Event TypePHONE SCREEN · Seen Mar 2026
  • Page Permission InheritancePHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
  • Percentage of Blocks Never EditedPHONE SCREEN · Seen Mar 2026
  • Versioned Document StorePHONE SCREEN · Seen Apr 2025
  • Top Error Types in a Time WindowONSITE INTERVIEW · Seen Jun 2026

Similar questions at other companies

  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
  • Text Editor, Part 2: Undo and RedoOpenAI · PHONE SCREENOpenAI interview questions
  • Text Editor OperationsMicrosoft · OAMicrosoft interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions

Interview reports that mention this question

  • Notion Interviews, Level Not Reported: 20 Experiences

Notion interview experiences

  • Notion Experienced SWE Interviews: 7 Experiences
  • Notion SWE New Grad Interviews: 3 Experiences
  • Notion SWE Intern Interviews and Debugging Round: 6 Experiences
  • Notion New Grad SWE Onsite Invitations: 2 Experiences
All Notion interview questionsSee Notion hiring insights
Saved
class Solution {
    public String[] runTextDocument(String[][] operations) {
        // Write your code here.
    }
}
Checking account…