An Elevator System Design interview question is one of the best interview questions to gauge the candidate’s grasp on the fundamentals of Computer Science. In addition, this can be extended in many different directions, making it an ideal problem to see how the candidate thinks. It’s easy to make it an object-oriented design problem. It can be used to discuss different data structures that will help in the implementation. If needed, it can be made even more complicated by adding multiple elevators serving the building, where a request button summons the most appropriate elevator. That is another nice optimization problem. But the core single elevator problem is often good enough to judge the ability of a candidate to see different trade-offs inherent in any design.
As always when an interviewer asks this question, it is always better to first understand what he is really looking for in the candidate. The best way to find out is to collect the requirements first.
1. An elevator can move up, down or standstill.
2. An elevator can transfer passengers from one floor in a building to another floor in the minimum time possible.
3. Elevator door can only open when it is standstill in a floor (i.e. not moving).
4. Let’s first discuss the number of floors that a building can have. The tallest building in the world is Burj Khalifa and it has around 163 floors. Let’s just assume that our system has 200 floors, which is still far greater than what the tallest building has. We cannot just assume some arbitrarily large number. When we are gathering requirements, we need to make sure that we are still collecting some reasonable requirements.
5. Burj Khalifa has around 57 elevators. We can assume in our system we have around 100 elevators.
6. Then there are some requirements related to each elevator like:
a. Number of passengers / Load on the elevator
b. Moving speed of the elevator
7. Now fourth requirement is about what we would like to minimize.
a. Do we like to minimize the wait time of the passengers?