Microsoft Round 2: Elevator LLD Problem:
A building with 50 floors. You have a lift which can take 20 people at a go. The lift can stop at any number of floors, but for any person who is being served by the lift, they have to reach from the entry floor to the destination floor within 5 stops. A lift will serve a new request only if it can maintain the rule of 5 stops for people who are already in the lift and also for the person sending the request.
This is an example case. A, B, C, D, E, F are denoting persons and corresponding values are source and destination floors. A 0 10 B 1 9 C 1 8 D 1 7 E 1 5 F 7 10
For this case, if Person A is entering at level 0, then the elevator can stop at 1 and it can serve Person B, C, D, and also Person F. As from going level 0 to 10, it will stop at maximum 5 places till reaching level 10 (floors on which it will stop will be 1, 7, 8, 9, 10).
This is the problem I faced in my Microsoft LLD round interview.
The main discussion was around the algorithm for the given constraint: the elevator should not stop more than 5 stops while serving one person. Currently, consider only one lift in one building.
What data structure and what optimal strategy would you use to solve this problem?