Bird
0
0

Identify the error in this state transition logic for a system with states idle, moving up, and moving down:

medium📝 Analysis Q14 of 15
LLD - Design — Elevator System
Identify the error in this state transition logic for a system with states idle, moving up, and moving down:
if state == 'idle' and event == 'move up':
    state = 'moving up'
elif state == 'moving up' and event == 'move down':
    state = 'moving down'
elif state == 'moving down' and event == 'stop':
    state = 'idle'
AMissing transition from idle to moving down
BMissing transition from idle to moving up
CIncorrect event name for stopping
DState variable is not updated
Step-by-Step Solution
Solution:
  1. Step 1: Review all possible transitions

    The code allows idle to moving up, moving up to moving down, and moving down to idle, but no direct transition from idle to moving down.
  2. Step 2: Identify missing transitions

    Since the system should allow moving down from idle, this transition is missing.
  3. Final Answer:

    Missing transition from idle to moving down -> Option A
  4. Quick Check:

    Check all valid transitions included [OK]
Quick Trick: Check if all state-event pairs have transitions [OK]
Common Mistakes:
MISTAKES
  • Assuming moving up can switch directly to moving down
  • Ignoring missing transitions from idle
  • Confusing event names with states

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes