Design a Solution Scheduler Service for a building with N floors (0 to N-1) and M lift cars.
Each lift navigates from one floor to another in 1 unit of time. You need to implement 2 APIs:
requestRide(fromFloor, toFloor): A passenger requests a ride from fromFloor to toFloor
nextAction(): Returns a list of states for each lift car. Valid states are:
UP: Lift moves up one floor
DOWN: Lift moves down one floor
OPEN_DOOR: Lift opens door for boarding/alighting
IDLE: Lift stays idle
Rules:
All lifts start at floor 0
nextAction() may be called at every time unit or sparsely
Lifts have infinite capacity
Loading and unloading passengers happens simultaneously during OPEN_DOOR
Duplicate ride requests (same fromFloor and toFloor) should be ignored
The scheduler should efficiently assign lifts to minimize wait time
Example:
`
N = 3 floors, M = 2 lifts
requestRide(0, 2) // Passenger at floor 0 wants to go to floor 2
requestRide(1, 0) // Passenger at floor 1 wants to go to floor 0
nextAction() -> ["OPEN_DOOR", "UP"]
// Lift 0 opens door at floor 0, Lift 1 goes up to floor 1
nextAction() -> ["UP", "OPEN_DOOR"]
// Lift 0 goes up, Lift 1 opens door at floor 1
nextAction() -> ["OPEN_DOOR", "DOWN"]
// Lift 0 at floor 2 opens door, Lift 1 goes down
nextAction() -> ["IDLE", "OPEN_DOOR"]
// Lift 0 idle, Lift 1 at floor 0 opens door
`
Methods
| Method | Parameters | Returns | Description |
|--------|------------|---------|-------------|
| requestRide | fromFloor, toFloor | None | Register a ride request from one floor to another |
| nextAction | - | list | Return the next action for each lift (UP, DOWN, OPEN_DOOR, or IDLE) |