Text Editor
InterviewTime limit0.3sMemory limit512 MB
Simulate a line editor with cursor movement, character deletion, and insertion commands, printing the final string.
- Level
Medium4 of 10
- Topics
- Stack, Simulation, String, Implementation
- Solved
- No attempts yet
Problem
Implement a simple editor for a single-line string. The editor stores only lowercase English letters, and the string can grow to at most 600,000 characters.
The editor has a cursor. The cursor can be at the beginning of the string, at the end of the string, or between two adjacent characters. If the current string has length L, there are L+1 possible cursor positions.
The editor supports the following four commands.
You are given the initial string and then the commands in order. Print the string left in the editor after all commands are executed. The cursor starts at the end of the initial string.
Input
The first line contains the initial string. It consists only of lowercase English letters and has length at most 100,000.
The second line contains the number of commands M. M is between 1 and 500,000, inclusive.
Each of the next M lines contains one command. Every command has one of the four forms described in the problem statement.
Output
Print one line: the string in the editor after all commands have been executed.