Bird
Raised Fist0

You need to design a game state manager that supports undo and redo of state changes. Which data structure combination is best suited for this?

hard📝 Trade-off Q8 of Q15
LLD - Design — Chess Game
You need to design a game state manager that supports undo and redo of state changes. Which data structure combination is best suited for this?
ALinked list with only forward pointers
BSingle queue for all states
CTwo stacks: one for undo, one for redo
DHash map of states to timestamps
Step-by-Step Solution
Solution:
  1. Step 1: Understand undo/redo requirements

    Undo requires going back to previous states; redo requires moving forward again.
  2. Step 2: Choose data structures supporting back and forth navigation

    Two stacks allow pushing states on undo and redo stacks, enabling easy undo/redo operations.
  3. Final Answer:

    Two stacks: one for undo, one for redo -> Option C
  4. Quick Check:

    Undo/redo = two stacks [OK]
Quick Trick: Use two stacks to manage undo and redo efficiently [OK]
Common Mistakes:
MISTAKES
  • Using queue which is FIFO, not suitable
  • Using singly linked list which lacks backward traversal
  • Using hash map which doesn't track order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes