Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-211

Redo Stack Behavior

Problem

Simulate a text editor with undo and redo stacks.

operations contains "type" (append values[i]), "undo" (move the last character to the redo stack), "redo" (restore the last undone character), or "current" (record the text so far). Typing clears the redo stack.

Return the list of recorded results (None for type, undo, and redo).

Hint

A new typed character discards everything on the redo stack.

Test cases

case 1
in: [["type","type","undo","current","redo","current"],["a","b",0,0,0,0]]
expected: [null,null,null,"a",null,"ab"]
case 2
in: [["redo"],[0]]
expected: [null]
case 3
in: [["type","undo","undo","current"],["x",0,0,0]]
expected: [null,null,null,""]
case 4
in: [["type","undo","type","redo","current"],["a",0,"b",0,0]]
expected: [null,null,null,null,"b"]
Starter codePython
def undo_redo(operations, values):
    # Your code here
    pass

4 test cases · run your code against them in the editor