Dsa
Stack
Hard
Undo Action Tracker
You are implementing an undo feature for a simple text editor. Each action can be either 'ADD X' (adding character X) or 'UNDO' (removing the last action). Write a program that processes a sequence of actions and outputs the final state of the text. If there are no actions, output an empty string.
Input format:
- Each action is provided on a new line, and the last input line will be 'END'.
Output format:
- A single line containing the final text after all actions.
Example:
Input:
ADD a
ADD b
UNDO
ADD c
END
Output:
a c
Key concepts
stackundotext manipulation
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