Amazon Interview Question for SDE-2s


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

I was asked the same question in one of the interviews and off-course couldn't do well in the interview.

There is 2 questions related to elevators that get asked
1.) Object oriented design for elevator system
2.) Scheduling of the elevator which is another complicated subject.

The following below should help with 1.).
Please note that the below content is from one of the papers on internet. unfortunately, i cannot link the web document here. search in google for "elevator system object oriented design" and you should find more details on the problem. It is domain cmu.edu.
---------------------------
Car: The car is being controlled to move up and down (in different speeds), to makestops at floors when necessary.

Button: The ElevatorControl class also controls the button class, which further generalizes two subclasses CarCallButton and HallCallButton. The control object
communicates with the Button objects, get the information whether a button is pressedand in turn controls the illumination of Button lights.

Indicator: There are two kinds of indicators in the system, the CarPositionIndicator and the CarDirectionIndicator (i.e. the CarLantern). The indicators are controlled to show the information about the current position and moving direction of the car.

Safety: Whenever an emergency happens according to the definition of emergency brake trigger in the requirement documentation, the ElevatorControl commands the Safety
---------------------------

- Algorithmy October 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

A good idea might be to also add an object for elevator doors

- Anonymous January 07, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not needed if you understand abstraction.

- Anonymous January 25, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

then problem here is that we can't have the 40 buttons or 60 buttons.
we can have indexed approach here to have button like
0, 10, 20, 30, 40 and corresponding we can 1,2,3,4,5,6,78,9,10 buttons.
On the same line we can have a solution with floors marked as A1,A2, A3 , B1, B2, B3. After this we can have indexed button A , B ,C instead of 10,20, 30.

- pankajanand18 September 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can just take a digital input, having 0 to 9 and enter button

- Avinash January 12, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Now a days we also see multiple lifts in a building. Lift A stops only at G,2,4,6,8...
while B stops at G, 1, 3, 5, 7..... to reduce the time taken to reach.

- ramprasad85 February 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let's get into little math here!!
Let's say there N number of lifts are there in building.
Each floor is expected to have at-least M Request panels/DisplayUnits(call them IOPanel).
Whole building can have total of P number of IOPanels.

IOPanel: 
-has an Identity.
-handles user input/output operations.
-creates a ElevatorRequest on behalf of USER.
-places request to MainRequestHandler.

Request:
-has an Identity
-knows sourceFloor
-knows targetFloor
-knows RequestOriginator(IOPanel)

MainRequestHandler:
-maintains RequestPool
-can Add a request to it's pool
-can delete a request to it's pool.
-For Each Request in RequestPool, 
    it Uses a Scheduler to assign the request to a ElevatorRequestHandler.
    remove request from pool.
-**Uses a schedular

Scheduler:
-uses SchedulerStrategy
-can observe the state of ElevatorRequestHandler(s) to come up with response.

SchedulerStrategy: 
- Abstract Strategy can have concrete strategy classes inheriting from this.

ElevatorRequestHandler: 
- processes the Request from it's pool.
- can control the Elevator accordingly. {start,stop,shutdown,set direction etc}

Elevator:
-knows it's current position.
-can move up based on command given by it's controller.
-can move down based on command given by it's controller.
-has Door (can open door/close door)


SchedulerStrategy => can be Strategy Pattern
MainRequestHandler and ElevatorRequestHandler(s) => can be Command Pattern

Now worry about scheduling for a large building. i.e. discuss a particular strategy and see how your strategy can fit in StrategyPattern.

- BrOkEN@! August 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The data structures involved should be some kind of circular priority queue, priority being lower floors and upper floors alternatively according to when the elevator is going up or coming down.

The functions would be like :

Start
- manually start the elevator
- allows pressing of button from outside the elevator to make a call

Stop
- manually stop the elevator

while the elevator is in started mode following functions would be applicable

while door is open at some floor
- keep count on the number of people entering and their weights
- if weight rises above the limit - generate an alert and stop until some people get out
- otherwise let people in
- for people inside allow them to enter the floor numbers of where they want to stop
- all these will be stored in the priority queue.
- when no one is coming in for a few minutes close the door and move

the elevator can move either up or down according the value pressed first when the queue was empty

while going up/down
- stop on each floor in the queue which comes in the way to the floor having the highest value/lowest.
- also stop at floors where the button for call has been pressed for going up/down respectively.
- at each stop open the doors and follow the above function
- when the floor with highest/lowest value is reached, check if the list is empty or not.
- if empty close the door and wait for some input at some floor from outside.

other input values can be like
- alarm button for emergencies
- fan on/off etc

- kr0821 December 30, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More