Execute Cursor-Based Text Editor Operations
Problem statement
Start with an empty document and cursor position 0. Each command is [operation,argument].
INSERT textinserts at the cursor and moves past it.LEFT xandRIGHT xmove without crossing an edge.BACKSPACE xremoves up to x characters immediately left of the cursor and moves to the deletion start.DELETE xremoves up to x characters immediately right of the cursor without moving it.PRINT xrecords characters at indices fromcursor-xthroughcursor+x, inclusive and clipped to the document.
Return recorded strings in print order.
Function
getPrintedStrings(commands: String[][]) → String[]Examples
Example 1
commands = [["Insert","addthis"],["Print","5"],["Left","4"],["Right","2"],["Backspace","1"],["Delete","1"],["Print","10"]]return = ["dthis","addts"]The print results are dthis and addts.
Example 2
commands = [["Insert","abc"],["Left","2"],["Insert","XY"],["Print","3"]]return = ["aXYbc"]Insertion at cursor one creates aXYbc and the cursor sits after XY.
Example 3
commands = [["Print","2"]]return = [""]Printing an empty document records an empty string.
Constraints
1 <= commands.length <= 5000.- The total inserted length is at most 5000.
- Numeric arguments are nonnegative decimal integers.