Document edit replay

Write codeEasy15 minFigma style

Your task

A note taking app replays the command log of one editing session. The document starts empty. Each command is one of four strings. "type|hello" appends that text to the end of the document. "trim|3" removes the last three characters, and removes everything if fewer than three remain. "undo" restores the document to the state it had before the most recent applied edit. "redo" reapplies the most recently undone edit. A type or a trim counts as an edit even when it changes nothing, and every new edit discards whatever could still be redone. An undo with nothing to undo, or a redo with nothing to redo, is ignored. Return the document text after the whole log has been replayed.

Examples

replay_editor_session(commands: list[str]) -> str
Example 1
Inputreplay_editor_session(["type|hel", "type|lo", "undo"])
Output"hel"
Example 2
Inputreplay_editor_session(["type|abc", "undo", "type|xyz", "redo"])
Output"xyz"
Example 3
Inputreplay_editor_session(["type|draft", "trim|2", "undo", "undo", "redo"])
Output"draft"