Problem · Design
Text Editor, Part 1: Basic Text Buffer
Learn this problemProblem 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]: inserttextimmediately before the character at the zero-basedposition. 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
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!.