Create an edit-history manager for a basic spreadsheet whose cells all begin empty. Operations are processed in order, and the user may reverse the most recent edit that has not already been reversed or restore the most recent edit that was reversed.
The initial version changes only one cell per edit:
SET cell value: Assign the specified value to the cell.UNDO: Reverse the newest undoable edit; do nothing when no such edit exists.REDO: Reapply the newest redoable edit; do nothing when no such edit exists.Rules:
SET operation discards every pending redo operation.GET cell reports the cell's current value. If the cell has never received a value or is empty now, return an empty string.process(operations: list[str]) -> list[str]
The returned list must contain the results of all GET operations, in the order those queries occur.
Input:
[
"SET A1 hello",
"SET A1 world",
"UNDO",
"GET A1",
"REDO",
"GET A1"
]
Output:
["hello", "world"]
Undo restores A1 to hello, and redo applies the second assignment again, producing world.
Input:
[
"SET A1 1",
"SET B1 2",
"UNDO",
"SET C1 3",
"REDO",
"GET B1",
"GET C1"
]
Output:
["", "3"]
The new assignment to C1 removes the pending redo for B1, so REDO has no effect; B1 is empty and C1 contains 3.
1 <= len(operations) <= 2 * 10^5A1 or BC27.SET value contains no newline characters and has length at most 10^4.O(1) processing per operation. Do not duplicate the complete spreadsheet state for every edit.