Amazon's "Elevator (OOD)" interview question focuses on designing a scalable elevator system for a multi-story building, emphasizing object-oriented principles, backend logic, web-scale considerations, machine learning for optimization, and system design.
Problem Statement
Design classes and logic for an elevator system in an N-story building with M elevators. The system must handle floor requests from users (both outside elevators on floors and inside for destinations), assign elevators efficiently, manage states (idle, moving up/down, doors opening/closing), and optimize for minimal wait times and travel distance. Support concurrent requests, safety features (overloads, emergencies), and scalability for high-traffic buildings. Use O(log N) time for request handling via efficient data structures like binary search trees or heaps.[3][7]
Key Requirements
- Functional: Process up/down calls per floor; inside-elevator destination buttons; elevator dispatching; door control; passenger counting.
- Non-Functional: Low latency (log N assignment); high availability; fault tolerance (e.g., one elevator fails); optimize power/maintenance via smart scheduling.[1][6]
- Optimizations: ML for predicting traffic patterns (e.g., rush hours send elevators to lobby); collective scanning or nearest elevator algorithms.[5]
Constraints
- N floors (typically 1-100+ stories); M elevators (1-20+).
- Max passengers per elevator: 8-15 (weight limit ~1000-2000 kg).
- Elevator speed: Constant travel time between floors (e.g., 5-10s/floor).
- Requests: Thousands per hour in peak times; concurrent handling required.
- No single point of failure; handle maintenance mode.[6][3]
Input/Output Examples
No formal I/O formats exist as this is an OOD problem, but typical simulation examples include:
Example 1: Single Request
- Input: User on floor 5 presses up; assign nearest idle elevator.
- Output: Elevator 2 (at floor 3, idle) moves to 5, doors open; user enters, presses 10; elevator goes to 10.[1]
Example 2: Concurrent Requests
- Input: Floor 1 up, floor 7 down, elevator inside requests floor 3.
- Output: Dispatcher assigns Elevator A (nearest to 1, heading up) to floor 1; Elevator B to 7 then 3; uses priority queue for log N selection.[7]
Example 3: Optimization Failure Case
- Input: Rush hour, multiple up requests from lobby.
- Output: ML model pre-positions 3 elevators at floor 1; reject overloads.[5][6]