Bird
0
0

In designing a state machine for an elevator with states idle, moving_up, and moving_down, how should the system respond if it receives a move_up request while currently moving_down?

hard📝 Trade-off Q8 of 15
LLD - Design — Elevator System
In designing a state machine for an elevator with states idle, moving_up, and moving_down, how should the system respond if it receives a move_up request while currently moving_down?
AImmediately switch to <code>moving_up</code> state, interrupting the current movement
BQueue the <code>move_up</code> request until the elevator reaches idle
CIgnore the <code>move_up</code> request until the current movement finishes
DReset the elevator to <code>idle</code> before processing the new request
Step-by-Step Solution
Solution:
  1. Step 1: Understand elevator movement constraints

    An elevator cannot abruptly reverse direction without stopping.
  2. Step 2: Consider safe state transitions

    The system should complete the current movement (moving_down) before moving up.
  3. Step 3: Handling conflicting requests

    Queue the move_up request to process after reaching idle.
  4. Final Answer:

    Queue the move_up request until the elevator reaches idle -> Option B
  5. Quick Check:

    Elevator must finish current direction before reversing [OK]
Quick Trick: Queue conflicting requests until idle state [OK]
Common Mistakes:
MISTAKES
  • Switching direction immediately causing unsafe behavior
  • Ignoring new requests leading to poor responsiveness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes