Simple Text Editor
Updated
Problem statement
Design a simple text editor that processes a list of commands and outputs the final text.
Supported commands:
type x→ Append characterxundo→ Remove the last typed characterredo→ Reapply the last undone character
Note: Typing a new character after an undo clears the redo history.
Function
finalText(commands: String[]) → StringExamples
Example 1
commands = ["type a", "type b", "undo", "redo", "type c"]return = "abc"Example 2
commands = ["type a", "type b", "type c", "undo", "undo", "type d"]return = "ad"Similar questions at other companies
- Implement a Queue Using Two StacksAmazon · ONSITE INTERVIEW
- Implement Stack Push and Pop OperationsLSEG · ONSITE INTERVIEWLSEG interview questions
- Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
- Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Undo and Redo Command HistoryNetflix · ONSITE INTERVIEWNetflix interview questions
- Asteroid CollisionAdobe · ONSITE INTERVIEWAdobe interview questions