FastPrepSimple Text Editor
Problems/Simple Text Editor

Simple Text Editor

Prophecy logoProphecy● EasyFULLTIMEONSITE INTERVIEW

Updated Sep 2026

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"

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