FastPrepText Editor, Part 1: Basic Text Buffer
Problems/Text Editor, Part 1: Basic Text Buffer

Text Editor, Part 1: Basic Text Buffer

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamples

Problem statement

Implement the text buffer for a text editor. The buffer begins empty and supports insertion, deletion, and reading the current text.

Supported operations

Each operation is a string array:

  • ["INSERT", position, text]: insert text immediately before the character at the zero-based position. A position equal to the current text length appends the text.
  • ["DELETE", start, end]: delete the characters in the half-open range [start, end).
  • ["GET"]: append the complete current text to the output.

Interview sequence

  1. Part 1: Basic Text Buffer
  2. Part 2: Undo and Redo

Function

processTextBuffer(operations: String[][]) → String[]

Examples

Example 1

operations = [["INSERT", "0", "hello"], ["INSERT", "5", "!"], ["GET"], ["DELETE", "1", "4"], ["GET"]]return = ["hello!", "ho!"]

The first query reads hello!. Deleting indices 1 through 3 removes ell, leaving ho!.

More OpenAI problems

  • Text Editor, Part 2: Undo and RedoPHONE SCREEN · Seen Apr 2026
  • Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] processTextBuffer(String[][] operations) {
      // write your code here
    }

}
Checking account…