Question bank › Stack
Dsa Stack Easy

Minimalist Undo/Redo Editor

You are building a text editor that supports three operations: 'WRITE [word]', 'UNDO', and 'REDO'. 1. 'WRITE [word]' appends a word and a single space to the text. It also clears the entire 'redo' history. 2. 'UNDO' removes the last word added to the text and moves it to the redo history. 3. 'REDO' takes the last word from the redo history and appends it back to the text. Input: A single line of space-separated commands. 'WRITE' is always followed by one word. Output: The final string after all operations, with trailing spaces trimmed. Example: Input: WRITE Hello WRITE World UNDO WRITE Coding REDO Output: Hello Coding (Explanation: 'Hello' added, 'World' added, 'World' undone, 'Coding' added - this clears the redo stack, so 'REDO' does nothing.)

Key concepts

stackdesignsimulation

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.