Bird
0
0
LLDsystem_design~10 mins

State management (idle, moving up, moving down) in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the initial state as idle.

LLD
state = '[1]'
Drag options to blanks, or click blank then click option'
Aidle
Bmoving_up
Cmoving_down
Dstopped
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'moving_up' or 'moving_down' as initial state.
2fill in blank
medium

Complete the code to change state to moving up when the elevator goes up.

LLD
if direction == 'up':
    state = '[1]'
Drag options to blanks, or click blank then click option'
Amoving_up
Bidle
Cmoving_down
Dstopped
Attempts:
3 left
💡 Hint
Common Mistakes
Setting state to 'idle' or 'moving_down' when direction is 'up'.
3fill in blank
hard

Fix the error in the state transition when the elevator moves down.

LLD
if direction == 'down':
    state = '[1]'
Drag options to blanks, or click blank then click option'
Aidle
Bmoving_up
Cmoving_down
Dstopped
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'moving_up' or 'idle' instead of 'moving_down'.
4fill in blank
hard

Fill both blanks to update the state correctly based on direction.

LLD
if direction == 'up':
    state = '[1]'
elif direction == 'down':
    state = '[2]'
Drag options to blanks, or click blank then click option'
Amoving_up
Bidle
Cmoving_down
Dstopped
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up states or using 'idle' incorrectly.
5fill in blank
hard

Fill all three blanks to implement a function that returns the next state based on current state and direction.

LLD
def next_state(current_state, direction):
    if current_state == 'idle' and direction == 'up':
        return '[1]'
    elif current_state == 'idle' and direction == 'down':
        return '[2]'
    else:
        return '[3]'
Drag options to blanks, or click blank then click option'
Amoving_up
Bmoving_down
Cidle
Dstopped
Attempts:
3 left
💡 Hint
Common Mistakes
Returning wrong states or not handling else case.