LinkedIn | Senior SDE | Phone Screen
Anonymous User
2705

Given two arrays representing an elevator problem, one array represents the weight of each person, and the second one represents the floor they are looking to reach.

For example:
[60, 20, 80, 180, 60]
and
[2, 2, 3, 3, 5]

The maximum weight the elevator can carry is 200.

Question: what's the least amount of distance the elevator has to travel? (From floor 1 to floor 2, distance will be 2-1=1)

Assume everyone starts on the first floor, and the elevator has to come back to the first floor to p ick up every group.

Assume people cannot skip the line. ie. 60 and 20 have to go before 80.

This part is relatively simple. Because I can't skip the line, just do a linear scan.

Follow up is much more difficult: what if people can skip the line? I wasn't sure how to solve it. Maybe with backtracking or DP?

Comments (9)