Elevator Scheduling Simulation
Problem statement
Simulate one elevator in a building with numFloors floors, numbered 0 to numFloors - 1. The elevator starts on floor 0 with direction UP and has no capacity limit. Return what it does in each tick.
How time works
Time moves in discrete steps called ticks. In each tick the elevator can do one of these:
- Move up or down exactly one floor.
- Stop to drop off passengers, board passengers, or both.
Either action takes a full tick, so the elevator cannot move and drop off or board in the same tick. Many passengers can get off and board during one stop. Changing direction takes no time. Passengers who reach their destination leave the simulation.
Examples
Example 1
numFloors = 4calls = ["0,2;0,3"]part = 1return = [[0,0,2],[1,0,0],[2,0,0],[2,1,0],[3,0,0],[3,1,0]]This is the walk-through from the task. The elevator is on floor 0 going up, and two passengers wait to go to floors 2 and 3.
- Board the passengers on floor
0:[0,0,2]. - Move to floor
1:[1,0,0]. - Move to floor
2:[2,0,0]. - Drop off the passenger going to floor
2:[2,1,0]. - Move to floor
3:[3,0,0]. - Drop off the passenger going to floor
3:[3,1,0].
Each step takes one tick. Everyone is done, so the simulation ends after six ticks.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 3 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.