Question: Question: Title: Text Editor with Advanced Undo / Redo Description: You are tasked with creating a more advanced text editor that supports multiple operations including

Question:
Title: Text Editor with Advanced Undo/Redo
Description:
You are tasked with creating a more advanced text editor that supports multiple operations including append, delete, print, undo, and redo. The editor should be capable of reversing previous undo operations through a redo functionality.
The text editor should handle the following operations:
Append a string: Add a string to the end of the current text.
Delete the last k characters: Remove the last k characters from the current text.
Print the ith character: Print the ith character of the current text (1-indexed).
Undo: Undo the last append or delete operation.
Redo: Redo the last undone operation.
Input Format:
The first line contains an integer n, the number of operations.
The next n lines contain one of the following operations:
"1": Append to the text.
"2": Delete the last k characters from the text.
"3": Print the ith character of the text.
"4": Undo the last operation.
"5": Redo the last undone operation.
Output Format:
For each "3" operation, print the ith character of the current text on a new line.
Constraints:
1<= n <=10^5
1<=|string|<=100
1<= k <=|current text|
1<= i <=|current text|
The total length of all append operations will not exceed 10^6 characters.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!