Bird
0
0

Given the following pseudo-code for state transitions, what will be the final state after these events: start at idle, move up, move down, idle?

medium📝 Analysis Q13 of 15
LLD - Design — Elevator System
Given the following pseudo-code for state transitions, what will be the final state after these events: start at idle, move up, move down, idle?
state = 'idle'
if event == 'move up' and state == 'idle':
    state = 'moving up'
elif event == 'move down' and state == 'idle':
    state = 'moving down'
elif event == 'stop' and state in ['moving up', 'moving down']:
    state = 'idle'
Aerror
Bmoving down
Cmoving up
Didle
Step-by-Step Solution
Solution:
  1. Step 1: Trace the events and state changes

    Start: state = 'idle'
    Event 'move up': matches first if, state = 'moving up'
    Event 'move down': does not match any condition (state != 'idle', event != 'stop'), no change
    Event 'idle': does not match any condition, no change. Final state = 'moving up'
  2. Step 2: Determine final state

    After all events, the state is 'moving up'.
  3. Final Answer:

    moving up -> Option C
  4. Quick Check:

    Trace confirms final state 'moving up' [OK]
Quick Trick: Follow events step-by-step to track state changes [OK]
Common Mistakes:
MISTAKES
  • Assuming move down changes state from moving up
  • Thinking event 'idle' triggers return to idle
  • Confusing event names with states

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes