Dsa
Queue
Warm-up
Undo Command History
A text editor maintains a history of the last K commands to support 'Undo'. If the history exceeds K commands, the oldest command is discarded (FIFO). Given the maximum size K and a sequence of N commands, output the final state of the history buffer from oldest to newest.
Example:
Input:
3
5
TYPE_A
TYPE_B
TYPE_C
DELETE
TYPE_D
Output: TYPE_C,DELETE,TYPE_D
Key concepts
queuefixed-size buffer
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