Recently I went to a technical interview in a big tech company for the front-end engineering role. Regardless of how I feel about their process and how unrelated the test was to the job, I found one of the questions interesting and thought it would be nice if I post my solution here.
Here’s the problem:
There is an elevator in a building with
Mfloors. This elevator can take a max of
Xpeople at a time or max of total weight
Y. Given that a set of people and their weight and the floor they need to stop, how many stops has the elevator taken to serve all the people? Consider the elevator serves in “first come first serve” basis and the order for the queue can not be changed.
Abe the weight of each person
A = [60, 80, 40].
Bbe the floors where each person needs to be dropped off
B = [2, 3, 5].
The building has 5 floors, maximum of 2 persons are allowed in the elevator at a time with max weight capacity being 200. For this example, the elevator would take total of 5 stops in floors: 2, 3, G, 5 and finally G.
And here’s my solution:
After I successfully submitted the solution, I searched Google to see if this question has been asked before, turns out it’s a common problem that is asked in programming tests and many people have solved it (for example this one).
I hope this solution comes in handy for anybody who’s willing to cheat a programming test. Hope you don’t though :-)