Bird
Raised Fist0

Find the bug in this state transition logic:

medium📝 Analysis Q7 of Q15
LLD - Design — Elevator System
Find the bug in this state transition logic:
if state == 'moving_up' and command == 'moveUp': state = 'moving_up'
elif state == 'moving_up' and command == 'stop': state = 'idle'
elif state == 'moving_up' and command == 'moveDown': state = 'moving_up'
AMoving down command does not change state from moving_up
BStop command incorrectly sets state to idle
CRepeated state assignment causes infinite loop
DNo bug, logic is correct
Step-by-Step Solution
Solution:
  1. Step 1: Review each condition

    MoveUp keeps state same, stop moves to idle, moveDown incorrectly keeps moving_up.
  2. Step 2: Identify expected behavior

    MoveDown command should change state to moving_down, not keep moving_up.
  3. Final Answer:

    Moving down command does not change state from moving_up -> Option A
  4. Quick Check:

    MoveDown should switch state, not stay same [OK]
Quick Trick: MoveDown command must change state from moving_up [OK]
Common Mistakes:
MISTAKES
  • Ignoring moveDown effect
  • Assuming no state change is correct
  • Confusing stop command effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes