Text Document History
Updated
Problem statement
Process operations against an initially empty text document.
["APPEND", text]appendstextto the end.["DELETE", count]removes the finalcountcharacters.["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