Problem · Stack

Simple Text Editor

Learn this problem
EasyPRProphecyFULLTIMEONSITE INTERVIEW

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"
drafts saved locally
public String finalText(String[] commands) {
  // write your code here
}
commands["type a", "type b", "undo", "redo", "type c"]
expected"abc"
checking account