Text Editor

Asked at NetflixOnsite

Reported by the problem's creator, not verified

You design a text editor that keeps its document as a single string. The document starts empty, and every edit happens at the end of the text: append adds characters there and delete removes characters from there. Each test creates one Editor instance and runs a sequence of method calls, recording every call's return value (None for methods that return nothing).

Examples

  1. Example 1

    Input: init = [], operations = [["append",["hello"]],["append",[" world"]],["text",[]],["delete",[3]],["text",[]],["undo",[]],["text",[]],["undo",[]],["text",[]],["undo",[]],["text",[]],["undo",[]],["undo",[]]]

    Output: [null,null,"hello world",3,"hello wo",true,"hello world",true,"hello",true,"",false,false]

    Explanation: delete(3) trims the text to hello wo. Each undo() reverts one edit in reverse order: the delete, then the append of world, then the append of hello. The last two undo() calls find no un-reverted edit and return False.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.