FastPrepSimple Text Editor
Problems/Simple Text Editor

Simple Text Editor

Prophecy logoProphecy● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamples

Problem statement

Design a simple text editor that processes a list of commands and outputs the final text.

Supported commands:

  • type x → Append character x
  • undo → Remove the last typed character
  • redo → Reapply the last undone character

Note: Typing a new character after an undo clears the redo history.

Function

finalText(commands: String[]) → String

Examples

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"
See Prophecy hiring insights
Saved
class Solution {
    public String finalText(String[] commands) {
      // write your code here
    }
}
Checking account…