20. Implement Undo & Redo
β GFG solution to the Implement Undo & Redo problem: build a text editor with append, undo, redo, and read operations using stack-based approach. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [[1 'A'], [1 'B'], [1 'C'], [2], [4], [3], [4]]
Output: ["AB", "ABC"]
Explanation:
1st query: Append('A'), Document contains "A".
2nd query: Append('B'), Document contains "AB".
3rd query: Append('C'), Document contains "ABC".
4th query: UNDO(), Last character is removed, Document contains "AB".
5th query: READ(), Document content "AB" will be printed.
6th query: REDO(), Document contains "ABC".
7th query: READ(), Document content "ABC" will be printed.Example 2
π Constraints
β
My Approach
Stack-Based Approach
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated