Text Editor, Part 2: Undo and Redo
Updated
Problem statement
Extend a text buffer with undo and redo history. The buffer begins empty.
Supported operations
Each operation is a string array:
["INSERT", position, text]: inserttextimmediately before the character at the zero-basedposition.["DELETE", start, end]: delete the characters in the half-open range[start, end).["UNDO"]: undo the most recent insert or delete that is still applied.["REDO"]: reapply the most recently undone operation.["GET"]: append the complete current text to the output.
Every insert and delete must be undoable. Executing a new insert or delete after an undo clears the redo history. UNDO or REDO does nothing when its corresponding history is empty.
Interview sequence
Function
processTextEditorHistory(operations: String[][]) → String[]Examples
Example 1
operations = [["INSERT", "0", "hello"], ["INSERT", "5", "!"], ["DELETE", "1", "4"], ["GET"], ["UNDO"], ["GET"], ["REDO"], ["GET"], ["UNDO"], ["INSERT", "5", "?"], ["REDO"], ["GET"]]return = ["ho!", "hello!", "ho!", "hello?!"]Undo restores the deleted substring and redo removes it again. After the second undo, inserting ? clears the redo history, so the following REDO has no effect.
More OpenAI Phone Screen questions
- Text Editor, Part 1: Basic Text BufferPHONE SCREEN · Seen Apr 2026
- Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
- Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
- Grid Infection with Recovery After D DaysPHONE SCREEN · Seen Nov 2026
- Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
- Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
- Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
- Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
- Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
- Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
- Text Editor OperationsMicrosoft · OAMicrosoft interview questions
- Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
- Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions