Problem, as an interviewer would state it:
"Implement an undo/redo system for a text editor using the Command pattern — each edit is an object with do() and undo() methods, and the system needs to support a real, deep undo/redo history."
Examples:
stack.execute(insertCommand("Hello", 0));
stack.undo(); // reverts the insert
stack.redo(); // re-applies it
Clarifying questions expected:
- What should happen to the redo history if a NEW action is performed after an undo — is it cleared, or preserved as a branch?
- Does the command need to store enough information to undo itself, or does the stack manage that separately?
- Is there a maximum history depth, or unbounded?
Code / implementation expected: Yes — real, direct proof of a real sequence of inserts, undos, and redos, including the critical case of a new action correctly clearing the redo stack.