Dsa
Stack
Medium
Undo Operation Tracker
Design a command interpreter that supports two commands: 'edit text' to set the text and 'undo' to revert to the last version of the text. You should implement an undo function that allows for reverting the latest edit.
Input Format:
A number n of commands followed by n lines of commands.
Output Format:
Print the final text after all commands have executed. If an undo is called first, it should print 'No previous edits' instead.
Example:
Input:
4
edit hello
edit world
undo
edit there
Output:
there
Key concepts
stackundocommands
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now