Code an elevator as a state machine. Asked in the final round technical interview stage. OOD/implementation.
Implement a single-elevator simulator that processes events one at a time and updates the elevator's state. The elevator starts at floor 0 with doors closed and can move one floor per tick.
def step_elevator(state, event):
state is a dict with keys: floor, direction, doors_open, targets, moving.event is one of: {"type": "call", "floor": int}, {"type": "select", "floor": int}, or {"type": "tick"}.call and select add a target floor if it is not already present.tick, if doors are open, close them first and do not move.targets.direction = "idle".Return the full updated state after each event.
def step_elevator(state, event):