## Amazon Interview Question

Country: United States

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

You have to keep in mind about the number of people going to use the elevator and number elevators. Once you have those values, divide the number of buttons(floors it will go) you are going to put in each elevator into ranges rather than all in in each elevator. So now your elevators will have range of floors it will travel. This reduce overall waiting time.

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

Elevators can be programmed so that they can only serve certain floors or floor ranges
So,using Divide and conquer method optimizes your problem by reducing the number of floors an elevator serves based on elevator location like (Higher the floor and less the number of floors,elevator serves)
You can also give priority based on the busy time

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

I would start my answer by trying to lay out some rules:

1) Once a passenger gets on the elevator, the elevator must deliver him to any floor in the direction he indicated while waiting for the elevator.
2) The elevator system must serve the extremes, so if an elevator is going down, and people are waiting on the bottom, it can't turn around to get more passengers on middle floors unless there's another elevator working toward the bottom.

The interviewer might challenge both rules. For rule #1, you would probably make an exception if you have just one passenger. For rule #2, an unethical elevator operator might decide overall throughput is worth temporarily standing people for a while (especially if they can take the stairs).

Once an elevator is empty, it needs to decide whether to work up or down, based on the other elevator's current travel plans. A greedy plan has you going to the nearest extreme, i.e. if the elevator is close to the top, go pick up the topmost passenger. But you need to account for other elevators maybe already being en route to that passenger (especially empty elevators that are already above you).

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

I think you have create a simple algorithm which will calculate the difference in current floor and called floor as well as the difference between the called floor and resultant floor.
Ex. if the lift is at 2nd floor and the next floor is 10th. If someone calls from 1st, it must go to first rather than moving up to the 10th.
That's what i think.
I can be wrong. What say?

Comment hidden because of low score. Click to expand.
0

I think that approach will not work in normal way. Let's consider a case.

Lift is going upwards, currently at Floor 2.
Some one calls at Floor 1 then it goes there instead of Floor 10
and take person from floor 1 and then start moving to floor 10 again someone call at floor 1.
By doing this lift will be in infinite loop in floor 1 and floor 2.

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

always takes the trip from bottom to top or top down first. so that it'll avoid the starving case. but surely you can do some compromise with greedy algorithm to decrease the waiting time. I don't think there's a perfect plan

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

In the morning, always try to get it to the bottom floor if no one is riding.

In the evening, move it to the floor where the fat engineers sit.

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

My suggestion would be. If we have 3 lifts for example then
1. one lift will entertain the guys for odd number floors.
2. Second lift will entertain even number floors.
3. Third lift will work as the normal lift which can stop on any floor.

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

Use Skiplist. (See wikipedia)
This is similar to Subway system, where there will be certain express trains and certain local trains. Similarly, there will be certain elevators, servicing major floors (where no. of people getting off is more) and other elevators will serve local floors. Reducing average wait time for all people to optimal

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

One solution which i saw at some places is that one lift serve even floors and other servers odd floors. Also most rushy floor is served by both lifts like one having cafeteria, as everyone wants to go there. Also divide and concur is a good solution here.

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

This is more like a job scheduling problem. I guess a combination of priority,shortest job first, and FCFS will be a good approach.

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.

### 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.