Loading...
Learn Design Elevator System — a key concept for LLD interviews.
You're designing the elevator system for a 20-story office tower. Each elevator needs to track its current floor, direction, and the list of floors it must visit. It should handle requests from inside (passengers pressing floor buttons) and outside (hall call buttons).
enum Direction { UP, DOWN, IDLE }
class Elevator {
private id: number
private currentFloor: number = 0
private direction: Direction = Direction.IDLE
private destinationFloors: SortedSet<number>
private capacity: number = 10
private currentLoad: number = 0
addDestination(floor: number): void { /* ... */ }
move(): void { /* ... */ }
isAvailable(): boolean { /* ... */ }
distanceTo(floor: number): number { /* ... */ }
}What's the best way to model an individual Elevator?