This video explains object-oriented design of a Elevator system with multiple lifts using state design pattern from list of problems on CodeZym.
Problem details : [ Ссылка ]
This question is asked in SDE-1, SDE-2 and Senior Software Engineer interviews.
This is a Java machine coding solution which is tested in a multithreaded environment on CodeZym.
Link to blog with code: [ Ссылка ]
Feel free to reach out to me on LinkedIn: [ Ссылка ]
Design patterns used: Observer Design Pattern and concepts from strategy design pattern.
Write code for low level design (object oriented design) of an Elevator Management System consisting of multiple lifts.
All the lifts are in the same building which has multiple floors.
Lifts are numbered 0 to lifts-1 and floors are numbered 0 to floors -1.
In a lift, maximum 10 people can be there at a given time.
For simplicity lets assume that each lift takes exactly one second (see tick() method below) to go to next floor while coming up or going down.
Also, when a lift stops on a floor, then time taken for one or more people to come in or go out of lift is zero seconds (or 0 tick()).
You have to code below methods.
METHOD : void init(int floors, int lifts, Helper02 helper) :
Initialize/reinitialize the elevator system and reset all your instance variables.
METHOD : int requestLift(int startFloor, int destinationFloor) :
On each floor users will enter destination floor on a keypad.
startFloor is the floor user is currently at.
Your code should return lift index from 0 to lifts-1 or -1 in case none of the lifts can be assigned to user.
The Lift assigned to request must be both ELIGIBLE and MOST OPTIMAL.
METHOD : tick() :
This method is called every second so that you can appropriately update lift states
METHOD : getLiftStates() :
returns a string list of size lifts, each item representing floor and direction of lift it will be an array of Strings in below format
METHOD : getNumberOfPeopleOnLift(int liftId) :
returns how many people are on a given lift right now.
METHOD : getLiftsStoppingOnFloor(int floor, char moveDirection) :
returns list of lift indexes which are going to stop on the given floor,
List of topics for this question:
Design elevator system
Design elevator system lld
elevator lld design
design lift (elevator) system
design lift
elevator low level design
elevator low level system design
lift low level design
lift lld
low level design of elevator
elevator object oriented design
system design elevator
state design pattern
Java
Machine coding
low level design
object oriented design
design patterns
design patterns in java
lld system design
lld interview question
lld interview
lld & hld system design
low level system design
machine coding
machine coding round
machine coding interview
object oriented programming
Ещё видео!