Problem
Implement undo/redo for a sequence of edit operations on a document (e.g. typing, deleting, or formatting a block). undo() reverts the most recent operation; redo() re-applies the most recently undone operation. A new edit after some undos discards the redo history.
Input / Output
undo() / redo() calls.Constraints
undo() on empty history and redo() with nothing to redo are no-ops.Example
type "a"; type "b" -> "ab"
undo() -> "a"
undo() -> ""
redo() -> "a"
type "c" -> "ac" // redo of "b" is now discarded