Number of Stops in Elevator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Number of Stops in Elevator

Hey Guys, I'm looking for solutions to solve this problem. The objective is to define the number of stops the elevator will take. A = [60, 80, 40] weight of each person B = [2, 3, 5] floor X = 2 (max number of people in the elevator) Y = 200 (max number of weight) For this case the solution would be N = 5, since the elevator took 60 plus 80 to floors number 2 and 3 (2 stops), then came back to 0 (3 stops), it went to 5 (4 stops) and it returned to 0 ( 5 stops). Can anyone solve this? I'm mostly looking for Python solutions but all other are very welcome. Cheers

19th Oct 2017, 10:46 AM
Diogo Santos
Diogo Santos - avatar
4 Answers
0
With this scenario there is no difference between solutions. You can choose any combination of two persons then the other one.
19th Oct 2017, 7:51 PM
Mahdi Kazemi
Mahdi Kazemi - avatar
0
Here is the python solution for the problem. Any suggestion pls let me know def solution(A, B, M, X, Y): currentPerson = 0 totalPersonCount = len(A) destinationFloors = [] totalWeightTwoPersons = 0 maxPersonCount = 0 totalTrips = 0 startElevator = False while currentPerson < totalPersonCount: if maxPersonCount + 1 <= X and totalWeightTwoPersons + A[currentPerson] <= Y: destinationFloors.append(B[currentPerson]) totalWeightTwoPersons += A[currentPerson] if currentPerson == totalPersonCount - 1: startElevator = True maxPersonCount += 1 currentPerson += 1 else: startElevator = True if startElevator: if len(destinationFloors) == 2 and destinationFloors[0] == destinationFloors[1]: totalTrips += 1 destinationFloors[:] = [] else: totalTrips += len(destinationFloors) destinationFloors[:] = [] startElevator = False maxPersonCount = 0 totalWeightTwoPersons = 0 if len(destinationFloors) == 0: totalTrips += 1 return totalTrips
29th Mar 2018, 7:12 AM
chandrasekar J
chandrasekar J - avatar
- 1
then how about solving for minimum stops
20th Oct 2017, 4:40 AM
sayan chandra
sayan chandra - avatar
- 1
Hey, Thats the purpose of the exercise. To design a program that will give you the min number of stops. This is an exercise from codility, a platform to test programmers for employment. I couldn't solve this exercise, and I'm still trying but with no success till now.
20th Oct 2017, 10:40 AM
Diogo Santos
Diogo Santos - avatar