Bird
0
0

If the Invoker stores commands in a stack, what happens when undo is called twice after executing three commands?

medium📝 Analysis Q5 of 15
LLD - Design — Tic-Tac-Toe Game
If the Invoker stores commands in a stack, what happens when undo is called twice after executing three commands?
AThe last two commands are undone in reverse order.
BThe first two commands are undone in execution order.
COnly the last command is undone twice.
DUndo has no effect after first call.
Step-by-Step Solution
Solution:
  1. Step 1: Recall stack behavior

    A stack is Last-In-First-Out (LIFO), so last commands are undone first.
  2. Step 2: Undo twice removes last two commands

    Calling undo twice pops and reverses last two commands in reverse order.
  3. Final Answer:

    The last two commands are undone in reverse order. -> Option A
  4. Quick Check:

    Undo twice = last two commands reversed [OK]
Quick Trick: Undo uses stack LIFO order [OK]
Common Mistakes:
MISTAKES
  • Undoing commands in execution order
  • Undoing same command twice
  • Assuming undo stops after first call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes