Problem · Stack
Simple Text Editor
Learn this problemProblem 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"