Text Editor
Asked at Netflix
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
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 tohello wo. Eachundo()reverts one edit in reverse order: the delete, then the append ofworld, then the append ofhello. The last twoundo()calls find no un-reverted edit and returnFalse.